Re: DB batch queries
| From: | Lukas Smith | Date: | Mon, 01 Nov 2004 11:25:55 +0000 |
| Subject: | Re: DB batch queries | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15266@lists.php.net to get a copy of this message | ||
Matthew Weier O'Phinney wrote:
* Aidan Lister <aidan@php.net>:There is even a executeMultiple method. Eitherway the simple solution is to split the queries somehow into an array and then writing a wrapper method that either does an implode() or a loop shouldnt be a big deal. regards, LukasHow do I do batch queries with DB? At the moment I'm doing: sqlite_exec($db->connection, $query); Where $query is a bunch of SQL statements.When you say 'batch' and 'a bunch of SQL statements', are you talking about a bunch of statements that are formed the same but have different data? I.e., something like the following:INSERT INTO table(col1, col2) VALUES(1, 2); INSERT INTO table(col1, col2) VALUES(2, 3); INSERT INTO table(col1, col2) VALUES(3, 4);If so, use DB's prepare and execute methods. You would do so like the following:$sth = $db->prepare('INSERT INTO table(col1, col2) VALUES(?,?)'); while (some condition) { $db->execute($sth, array($val1, $val2)); }I don't know if prepare and execute work well with sqlite, however; someone else will have to weigh in on that.