Re: execute/prepare for tutorial (was Re: [PEAR-DEV] last Pear.php.in and DB.php commit)
| From: | Martin Jansen | Date: | Fri, 20 Apr 2001 07:14:58 +0000 |
| Subject: | Re: execute/prepare for tutorial (was Re: [PEAR-DEV] last Pear.php.in and DB.php commit) | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-279@lists.php.net to get a copy of this message | ||
On 19 Apr 2001 14:53:49 -0400, Stig Sæther Bakken wrote:
>A really silly example:
>
>$alldata = array(
> array(1, 'one', 'en),
> array(2, 'two', 'to'),
> array(3, 'three', 'tre'),
> array(4, 'four', 'fire)
>);
>$sth = $dbh->prepare("INSERT INTO numbers VALUES(?,?,?)");
>foreach ($alldata as $row) {
> $dbh->execute($sth, $row);
>}
>
>For MySQL, a new query is parsed and executed for every execute,
IIRC MySQL also supports a syntax like
"INSERT INTO <table> (f1,f2) VALUES ('x','y','z'),
('a','b','c')".
Using this syntax we could perhaps avoid building a new query
for each value of the array when using INSERT.
-Martin