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

From: Date: Thu, 19 Apr 2001 18:53:49 +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-276@lists.php.net to get a copy of this message
["Tomas V.V.Cox" <cox@idecnet.com>] > "Tomas V.V.Cox" wrote: > > > > Stig Sæther Bakken wrote: > > > > > > > Nice hack Stig, let's hurry up to document it :) > > > > It is now documented in section "II.3. Taking automatic actions on > errors", also is done the "I.4. Quick data retrieving" chapter which > covers the get* methods. > > Now I need some feedback on how works the "execute/prepare" stuff, > someone? Some examples would help a lot. 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, but for Oracle the parse is done only once, and this may speed up your queries a lot. Here's an example of a file placeholder: $myfile = "/tmp/image.jpg"; $sth = $dbh->prepare("INSERT INTO images (?, &)"); $dbh->execute($sth, array("this is me", $myfile)); After I commit a bugfix that I have on my laptop, you can use parameter arrays in the getXxx methods too: $ver = $dbh->getOne("SELECT stableversion FROM pacakges WHERE name = ?", array($package)); - Stig -- Stig Sæther Bakken <ssb@fast.no> Fast Search & Transfer ASA, Trondheim, Norway

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