joomla-dbo

Insert multiple rows using a single query

与世无争的帅哥 提交于 2019-12-06 22:38:20
问题 Can Joomla's DB object add multiple rows at once? MySQL can do this like so: INSERT INTO x (a,b) VALUES ('1', 'one'), ('2', 'two'), ('3', 'three') But can Joomla's own functions achieve the same thing in a single query? Currently I am doing a loop to insert each row (same table) in separate query. Not a good idea when dealing with tons of rows at once. 回答1: In your model you can do this: $db = $this->getDBO(); $query = " INSERT INTO x (a,b) VALUES ('1', 'one'), ('2', 'two'), ('3', 'three') ";

Insert multiple rows using a single query

核能气质少年 提交于 2019-12-05 03:06:06
Can Joomla's DB object add multiple rows at once? MySQL can do this like so: INSERT INTO x (a,b) VALUES ('1', 'one'), ('2', 'two'), ('3', 'three') But can Joomla's own functions achieve the same thing in a single query? Currently I am doing a loop to insert each row (same table) in separate query. Not a good idea when dealing with tons of rows at once. In your model you can do this: $db = $this->getDBO(); $query = " INSERT INTO x (a,b) VALUES ('1', 'one'), ('2', 'two'), ('3', 'three') "; $db->setQuery($query); $db->query(); If you are outside your model you need to get the DB object like so: