note 100850 added to pdo.exec
| From: | hungry dot rahly at gmail dot com | Date: | Thu, 11 Nov 2010 01:24:54 +0000 |
| Subject: | note 100850 added to pdo.exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173932@lists.php.net to get a copy of this message | ||
For those that want an exec that handles params like prepare/execute does. You can simulate this
with another function
class Real_PDO extends PDO {
public function execParams($sql, $params) {
$stm = $this->prepare($sql);
$result = false;
if( $stm && $stm->execute($params) ) {
$result = $stm->rowCount();
while( $stm->fetch(PDO::FETCH_ASSOC) ) {
}
}
return $result;
}
}
Remember though, if you are doing a lot of inserts, you'll want to do it the manual way, as the
prepare statement will speed up when doing multiple executes(inserts). I use this so I can place
all my SQL statements in one place, and have auto safe quoting against sql-injections.
If you are wondering about the fetch after, remember some databases can return data SELECT-like data
from REMOVE/INSERTS. In the case of PostgreSQL, you can have it return you all records that were
actually removed, or have the insert return the records after the insert/post field functions, and
io trigger fire, to give you normalized data.
define("BLAH_INSERT", "INSERT INTO blah (id,data) VALUES(?,?)");
$pdo = new Real_PDO("connect string");
$data = array("1", "2");
$pdo->execParams(BLAH_INSERT, $data);
----
Server IP: 69.147.83.197
Probable Submitter: 173.161.150.137
----
Manual Page -- http://www.php.net/manual/en/pdo.exec.php
Edit -- https://master.php.net/note/edit/100850
Del: integrated -- https://master.php.net/note/delete/100850/integrated
Del: useless -- https://master.php.net/note/delete/100850/useless
Del: bad code -- https://master.php.net/note/delete/100850/bad+code
Del: spam -- https://master.php.net/note/delete/100850/spam
Del: non-english -- https://master.php.net/note/delete/100850/non-english
Del: in docs -- https://master.php.net/note/delete/100850/in+docs
Del: other reasons-- https://master.php.net/note/delete/100850
Reject -- https://master.php.net/note/reject/100850
Search -- https://master.php.net/manage/user-notes.php