php - 一个查询中的多个插入 Joomla

标签 php mysql 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 方法的文档 block

/**
 * 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')) 如果有稍后我有机会传入一个代表不同字段名称数组的变量。

关于php - 一个查询中的多个插入 Joomla,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31192372/

相关文章:

php - 安卓连接错误: Gralloc pipe failed

php - 如何将 foreach 循环或 for 循环分成 10 条记录

php - 想要在php中下载excel文件时显示进度条

php - mysql表中保存图片源的方法

mysql - MySQL 查询中的 DATEDIFF

mysql - 什么是 SFW 查询?

mysql - DBMS 如何解决以下查询?

seo - Joomla 1.5 文章元关键字和描述管理

joomla - 将 Joomla 网站改版为 Google 搜索引擎

MySQL 加载缓慢 - 分页