一个查询 Joomla 中的多个插入
Multiple INSERTS in one query Joomla
如何进行多次插入,例如:
$query = "INSERT INTO `table` (`fied1`, `field2`, `field3`) VALUES ('one', 'two', 'three'),('four', 'five', 'six');
INSERT INTO `table` (`fied1`, `field2`, `field3`) VALUES ('seven', 'eight', 'nine'),('ten', 'eleven', 'twelve');"
$db->setQuery($query);
$db->query();
我无法拆分此查询,因为我是从大型文本文件中获取它的。
这是 insert
方法的文档块
/**
* Add a table name to the INSERT clause of the query.
*
* Note that you must not mix insert, update, delete and select method calls when building a query.
*
* Usage:
* $query->insert('#__a')->set('id = 1');
* $query->insert('#__a')->columns('id, title')->values('1,2')->values('3,4');
* $query->insert('#__a')->columns('id, title')->values(array('1,2', '3,4'));
*
* @param mixed $table The name of the table to insert data into.
* @param boolean $incrementField The name of the field to auto increment.
*
* @return JDatabaseQuery Returns this object to allow chaining.
*
* @since 11.1
*/
类似
$query->insert('table')
->columns(`fied1`, `field2`, `field3`)
->values(array('one, two, three', 'four, five, six'));
在线我认为您可能在第一个字段名称上有拼写错误,我可能会使用 $db->quoteName(array('field1', 'field2', field3'))
如果有机会我可以稍后传递一个代表不同字段名称数组的变量。
如何进行多次插入,例如:
$query = "INSERT INTO `table` (`fied1`, `field2`, `field3`) VALUES ('one', 'two', 'three'),('four', 'five', 'six');
INSERT INTO `table` (`fied1`, `field2`, `field3`) VALUES ('seven', 'eight', 'nine'),('ten', 'eleven', 'twelve');"
$db->setQuery($query);
$db->query();
我无法拆分此查询,因为我是从大型文本文件中获取它的。
这是 insert
方法的文档块
/**
* Add a table name to the INSERT clause of the query.
*
* Note that you must not mix insert, update, delete and select method calls when building a query.
*
* Usage:
* $query->insert('#__a')->set('id = 1');
* $query->insert('#__a')->columns('id, title')->values('1,2')->values('3,4');
* $query->insert('#__a')->columns('id, title')->values(array('1,2', '3,4'));
*
* @param mixed $table The name of the table to insert data into.
* @param boolean $incrementField The name of the field to auto increment.
*
* @return JDatabaseQuery Returns this object to allow chaining.
*
* @since 11.1
*/
类似
$query->insert('table')
->columns(`fied1`, `field2`, `field3`)
->values(array('one, two, three', 'four, five, six'));
在线我认为您可能在第一个字段名称上有拼写错误,我可能会使用 $db->quoteName(array('field1', 'field2', field3'))
如果有机会我可以稍后传递一个代表不同字段名称数组的变量。