Re: DB batch queries
| From: | Matthew Weier O'Phinney | Date: | Sun, 31 Oct 2004 13:31:28 +0000 |
| Subject: | Re: DB batch queries | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15243@lists.php.net to get a copy of this message | ||
* Aidan Lister <aidan@php.net>:
> How 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.
--
Matthew Weier O'Phinney | mailto:matthew@garden.org
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org