note 75070 added to function.PDO-exec
| From: | jonatchemdotumassdotedu at osu1 dot php dot net | Date: | Thu, 10 May 2007 21:12:39 +0000 |
| Subject: | note 75070 added to function.PDO-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126396@lists.php.net to get a copy of this message | ||
If you do this:
$res = $dbh->query("SELECT * FROM sessions WHERE session_id =
'$p_sessID'");
$l_records = $res->fetch(PDO::FETCH_ASSOC);
if( $l_records ) {
// ...update session-data
$l_theQuery = "UPDATE sessions SET session_expires='$newExp',
session_data='$p_sessData' WHERE session_id='$p_sessID'";
echo $l_theQuery;
$l_stmt = $this->db->prepare($l_theQuery);
if ( $l_stmt ) {
$l_rows = $l_stmt->execute();
}
}
You will get nothing.
But do this:
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
Prior to the code above, you will get this:
"PDO::prepare(): SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other
unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code
is only ever going to run against mysql, you may enable query buffering by setting the
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute."
So, instead of fetch(), use fetchAll(), it will make you less insane.
Incidentally, the INSERT statement that I was issuing, if the record that I needed to update
didn't yet exist, after the initial fetch() command worked perfectly.
Changing to fetchAll() fixed it.
----
Server IP: 69.39.81.135
Probable Submitter: 128.119.52.172
----
Manual Page -- http://www.php.net/manual/en/function.PDO-exec.php
Edit -- https://master.php.net/note/edit/75070
Del: integrated -- https://master.php.net/note/delete/75070/integrated
Del: useless -- https://master.php.net/note/delete/75070/useless
Del: bad code -- https://master.php.net/note/delete/75070/bad+code
Del: spam -- https://master.php.net/note/delete/75070/spam
Del: non-english -- https://master.php.net/note/delete/75070/non-english
Del: in docs -- https://master.php.net/note/delete/75070/in+docs
Del: other reasons-- https://master.php.net/note/delete/75070
Reject -- https://master.php.net/note/reject/75070
Search -- https://master.php.net/manage/user-notes.php