Re: [PATCH] DB / autoPrepare()

From: Date: Sun, 09 Jun 2002 14:11:02 +0000
Subject: Re: [PATCH] DB / autoPrepare()
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-6814@lists.php.net to get a copy of this message
MARTY Fabien wrote: > > Hello, > > I made patches to add autoPrepare() method in PEAR_DB. If you don't know > what it is about, i have put the first mail of the thread at the end of this > one. > > So to add it, we need a little patch to add two constants (DB_diff.txt) at > DB.php and a patch to add the autoPrepare() method at common.php > (common_diff.txt). > > With it, you can use : > > // --- INSER QUERIES --- > $data = array( > 'field1' => $value1, > 'field2' => $value2, > 'field3' => $value3, > (...) > ); > $prep = $db->autoPrepare('table', $data, DB_AUTOQUERY_INSERT); > // will make and prepare the sql query : > // INSERT INTO table (field1, field2, field3, ...) VALUES (?, ?, ?, ...) > $db->execute($prep, array_values($data)); > > // --- UPDATE QUERIES --- > $data = array( > 'fieldx' = $newValueX, > 'fieldy' = $newValueY > ); > $prep = $db->autoPrepare('table', $data, DB_AUTOQUERY_UDPATE, 'id=4'); > // will make and prepare the sql query : > // UPDATE table SET fieldx=?,fieldy=? WHERE id=4 > $db->execute($prep, array_values($data)); > I found my self doing that many times. IMO this belongs more to a SQL Builder class, but I agree that this simple facility (more needed that one think) could be added. +1 here Tomas V.V.Cox

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