#47655 [Bgs]: PDO MySQL prepare is allways emulated
| From: | info at chromosoft dot be | Date: | Sun, 15 Mar 2009 08:13:18 +0000 |
| Subject: | #47655 [Bgs]: PDO MySQL prepare is allways emulated | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-134710@lists.php.net to get a copy of this message | ||
ID: 47655
User updated by: info at chromosoft dot be
Reported By: info at chromosoft dot be
Status: Bogus
Bug Type: PDO related
Operating System: Ubuntu
PHP Version: 5.2CVS-2009-03-14 (snap)
New Comment:
It's correct, now I have another problem with prepare. The system say
"FATAL ERROR : 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."
And this on a execute function (not on query or fetch) and not on the
first execute on this statement, and the MYSQL_ATTR_USE_BUFFERED_QUERY
attribute is turn ON.
If I turn ON the ATTR_EMULATE_PREPARES the program work correctly but
without a real prepare.
Previous Comments:
------------------------------------------------------------------------
[2009-03-15 06:41:55] info at chromosoft dot be
Great, it works. But there is not much documentation on this option.
And I never thought that by default it is FALSE by default/
Thanks
------------------------------------------------------------------------
[2009-03-14 13:57:26] scottmac@php.net
This was intended due to the mysql api not being quite ready when PDO
was written. I believe you can use
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
But there might be bugs with this.
------------------------------------------------------------------------
[2009-03-14 07:46:43] info at chromosoft dot be
Description:
------------
Hi,
The prepare is allways emulated on the mysql DB.
But if you use mysqli the prepare work correctly.
MySQL : 5.0.51a
PHP : 5.2.4-2ubuntu5.5
Reproduce code:
---------------
Code with PDO :
$dbh = new PDO('mysql:host=localhost;dbname=db', 'root' , '');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $dbh->prepare('select * from tt where a = ?');
$sth->execute(array(1));
$sth->fetch();
unset($sth);
Code with Mysqli :
$mysqli = new mysqli("localhost", "root", "", "db");
$a = 5;
if ($stmt = $mysqli->prepare("select * from tt where a = ?"))
{
$stmt->bind_param("i", $a);
$stmt->execute();
}
$mysqli->close();
Actual result:
--------------
Log with PDO
30 Connect root@localhost on db
30 Query select * from tt where a = '1'
30 Quit
Log with Mysqli
31 Connect root@localhost on db
31 Prepare [1] select * from tt where a = ?
31 Execute [1] select * from tt where a = 5
31 Quit
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47655&edit=1