Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183506 is a reply to message #183501] |
Tue, 29 October 2013 12:10 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
Thomas Mlynarczyk wrote:
> When I do this:
>
> $pdo = new PDO( /* MySQL connection */ );
> // $pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
> $stmt = $pdo->prepare( 'SELECT 5 + "Five"' );
> $stmt->execute();
> var_dump( $pdo->query( 'SHOW WARNINGS' )
> ->fetchAll( PDO::FETCH_ASSOC ) );
>
> I get a warning back:
>
> Warning 1292 Truncated incorrect DOUBLE value: 'Five'
>
> But when I uncomment the second line (disabling emulation of prepared
> statements), "SHOW WARNINGS" returns an empty array. Why?
I cannot reproduce that.
---------------------------------------------------------------------------
$ php -r '
$pdo = new PDO("mysql:host=localhost", "…", "…");
$stmt = $pdo->prepare("SELECT 5 + \"Five\"");
$stmt->execute();
var_dump($pdo->query("SHOW WARNINGS")->fetchAll(PDO::FETCH_ASSOC));
var_dump($stmt->fetchAll());'
array(1) {
[0] =>
array(3) {
'Level' =>
string(7) "Warning"
'Code' =>
string(4) "1292"
'Message' =>
string(40) "Truncated incorrect DOUBLE value: 'Five'"
}
}
array(1) {
[0] =>
array(2) {
'5 + "Five"' =>
string(1) "5"
[0] =>
string(1) "5"
}
}
$ php -r '
$pdo = new PDO("mysql:host=localhost", "…", "…");
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$stmt = $pdo->prepare("SELECT 5 + \"Five\"");
$stmt->execute();
var_dump($pdo->query("SHOW WARNINGS")->fetchAll(PDO::FETCH_ASSOC));
var_dump($stmt->fetchAll());'
array(1) {
[0] =>
array(3) {
'Level' =>
string(7) "Warning"
'Code' =>
string(4) "1292"
'Message' =>
string(40) "Truncated incorrect DOUBLE value: 'Five'"
}
}
array(1) {
[0] =>
array(2) {
'5 + "Five"' =>
string(1) "5"
[0] =>
string(1) "5"
}
}
$ php -v
PHP 5.4.15-1 (cli) (built: May 12 2013 12:17:45)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with XCache v3.0.1, Copyright (c) 2005-2013, by mOo
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
with XCache Optimizer v3.0.1, Copyright (c) 2005-2013, by mOo
with XCache Cacher v3.0.1, Copyright (c) 2005-2013, by mOo
with XCache Coverager v3.0.1, Copyright (c) 2005-2013, by mOo
$ mysql -V
mysql Ver 14.14 Distrib 5.5.33, for debian-linux-gnu (i686) using readline
6.2
---------------------------------------------------------------------------
PDO::ATTR_EMULATE_PREPARES == false should be the effective default for
PDO_MySQL unless you are using an ancient MySQL version (why?) that does not
support Prepared Statements.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(at)news(dot)demon(dot)co(dot)uk>
|
|
|