Re: execute/prepare for tutorial (was Re: [PEAR-DEV] last Pear.php.in and DB.php commit)

From: Date: Fri, 20 Apr 2001 07:57:21 +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-280@lists.php.net to get a copy of this message
["Martin Jansen" <mj@php.net>] > 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. Cool. It's a bit tricky though, because if you are going to wait for more execute() calls to buffer up parameter data, you don't really know when to actually do the query. But in executeMultiple() it would be a piece of cake to do it. - Stig -- Stig Sæther Bakken <ssb@fast.no> Fast Search & Transfer ASA, Trondheim, Norway

« previous php.pear.dev (#280) next »