RE: [PEAR-DEV] Question re:DB package interaction with MySQL
| From: | Ben XO | Date: | Fri, 24 Feb 2006 03:22:17 +0000 |
| Subject: | RE: [PEAR-DEV] Question re:DB package interaction with MySQL | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-41469@lists.php.net to get a copy of this message | ||
There is a very slight "gotcha" with the 2nd insert syntax: it's very easy
to make a query so long that it fails (mysql gives an error about
"max_packet exceeded" I think) so you have to make sure you limit the size
of your insert.
--
Ben XO
-----Original Message-----
From: Frank F [mailto:frank@booksku.com]
Sent: 24 February 2006 02:51
To: pear-dev@lists.php.net
Subject: [PEAR-DEV] Question re:DB package interaction with MySQL
As I understand it, given the following code...
$col_names = array ('col1','col2');
$rand = array(
array('12341234', '345782'),
array('23423', '0983450934')
);
$dsn = 'mysql://root:secret@localhost/database1';
$db =& DB::connect($dsn);
$sth = $db->autoPrepare('randtest',$col_names,DB_AUTOQUERY_INSERT);
if (DB::isError($sth)) die ($sth->getMessage());
$sth = $db->executeMultiple($sth, $rand);
...DB will create and send two separate INSERT queries. My question is, why
does DB create two separate queries, when MySQL's capable of combining
multiple INSERTS into a single statement? (i.e. INSERT INTO randtest VALUES
('12341234', '345782'), ('23423', '0983450934');)
I ran a slightly more complex test, with a pre-generated set of 100,000
rows, and DB took 40-60 seconds to insert, whereas everything rolled into a
single query took a single second to insert.
It seems the alternate syntax would result in a huge performance gain
here...
--
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php