FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » PDO - Cannot retrieve warnings with emulated prepares disabled
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
PDO - Cannot retrieve warnings with emulated prepares disabled [message #183501] Mon, 28 October 2013 22:30 Go to next message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma: 0
Senior Member
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?

How can I get warnings and notices from MySQL in that case? PDO doesn't
seem to offer a method for retrieving them -- only for errors.

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183506 is a reply to message #183501] Tue, 29 October 2013 12:10 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
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>
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183507 is a reply to message #183506] Tue, 29 October 2013 12:23 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <12356089(dot)gSGYd4PIy3(at)PointedEars(dot)de>, Thomas 'PointedEars'
Lahn <PointedEars(at)web(dot)de> wrote:

> 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>

I take it you've been in touch with Mr. Cornford to point out that
there is no "javascript".

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183508 is a reply to message #183506] Tue, 29 October 2013 12:31 Go to previous messageGo to next message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma: 0
Senior Member
Thomas 'PointedEars' Lahn schrieb:
> 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.

I just checked on a different server (more recent versions of both PHP
and MySQL) and indeed, there it works.

> PHP 5.4.15-1 (cli) (built: May 12 2013 12:17:45)
> mysql Ver 14.14 Distrib 5.5.33, for debian-linux-gnu (i686) using readline
> 6.2

PHP 5.4.8
MySQL 5.1.41

Hm. So it could either be a bug that was fixed in a later version or I
somehow messed up my local installation.

> 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.

My MySQL version does support them. Still, PDO's default seems to be
"on" for the emulation.

Greetings,
Thomas


--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183509 is a reply to message #183508] Tue, 29 October 2013 12:47 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Thomas Mlynarczyk wrote:

> Thomas 'PointedEars' Lahn schrieb:
>> PHP 5.4.15-1 (cli) (built: May 12 2013 12:17:45)
>> mysql Ver 14.14 Distrib 5.5.33, for debian-linux-gnu (i686) using
>> readline 6.2
>
> PHP 5.4.8
> MySQL 5.1.41
>
> Hm. So it could either be a bug that was fixed in a later version or I
> somehow messed up my local installation.

I presume reading the changelog will tell.

>> 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.
>
> My MySQL version does support them. Still, PDO's default seems to be
> "on" for the emulation.

Not here; the attribute is not even supported:

$ php -r '
$pdo = new PDO("mysql:host=localhost", "…", "…");
var_dump($pdo->getAttribute(PDO::ATTR_EMULATE_PREPARES));'
PHP Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support
this function: driver does not support that attribute in Command line code
on line 3
PHP Stack trace:
PHP 1. {main}() Command line code:0
PHP 2. PDO->getAttribute() Command line code:3
bool(false)

<http://php.net/manual/en/pdo.getattribute.php>
<http://php.net/manual/en/ref.pdo-mysql.php>


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183510 is a reply to message #183508] Tue, 29 October 2013 12:58 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/29/2013 8:31 AM, Thomas Mlynarczyk wrote:
> Thomas 'PointedEars' Lahn schrieb:
<snip>
>> 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.
>
> My MySQL version does support them. Still, PDO's default seems to be
> "on" for the emulation.
>
> Greetings,
> Thomas
>

Thomas,

I could be wrong, but from my experience, the mysql driver has never
supported prepared statements, while the mysqli driver has always
supported them. This is why PDO has to emulate the prepared statements.

If you disable emulation with a mysql connection, I would expect errors
in the execution. What is the return value from your prepare() and
execute() calls?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183511 is a reply to message #183510] Tue, 29 October 2013 15:22 Go to previous messageGo to next message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma: 0
Senior Member
Jerry Stuckle schrieb:

> I could be wrong, but from my experience, the mysql driver has never
> supported prepared statements, while the mysqli driver has always
> supported them. This is why PDO has to emulate the prepared statements.

This is what PDO tells me about the driver being used:
PDO::ATTR_CLIENT_VERSION => mysqlnd 5.0.10 - 20111026

> If you disable emulation with a mysql connection, I would expect errors
> in the execution. What is the return value from your prepare() and
> execute() calls?

Prepare() returns a PDOStatement object and execute returns true.

Everything works fine with PDO::ATTR_EMULATE_PREPARES == false (except
for the issue with SHOW WARNINGS) and consistent with the assumption
that prepared statements are indeed supported.

$pdo->prepare( 'invalid' ) will return false; with emulated prepares it
will return a PDOStatement object -- both as expected.

With emulated prepares,

$stmt = $pdo->prepare( 'SELECT * FROM mytable LIMIT ?' );
$stmt->execute( [ 4 ] );

will give me a syntax error complaining about "LIMIT '4'", whereas with
PDO::ATTR_EMULATE_PREPARES == false the query works fine (proving that
the ? placeholder was indeed replaced with (int) 4 instead of (string) '4'.

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183512 is a reply to message #183509] Tue, 29 October 2013 15:26 Go to previous messageGo to next message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma: 0
Senior Member
Thomas 'PointedEars' Lahn schrieb:

> I presume reading the changelog will tell.

I couldn't find anything relating to this issue there.

>>> 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.
>> My MySQL version does support them. Still, PDO's default seems to be
>> "on" for the emulation.
>
> Not here; the attribute is not even supported:
>
> $ php -r '
> $pdo = new PDO("mysql:host=localhost", "…", "…");
> var_dump($pdo->getAttribute(PDO::ATTR_EMULATE_PREPARES));'
> PHP Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support
> this function: driver does not support that attribute in Command line code
> on line 3
> PHP Stack trace:
> PHP 1. {main}() Command line code:0
> PHP 2. PDO->getAttribute() Command line code:3
> bool(false)

Yes, I get that error too -- which is all the more confusing, since
otherwise the behaviour with PDO::ATTR_EMULATE_PREPARES == false is
consistent with the assumption that prepared statements are indeed
supported. See my reply to Jerry.

Greetings,
Thomas


--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183513 is a reply to message #183512] Tue, 29 October 2013 18:19 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Thomas Mlynarczyk wrote:

> Thomas 'PointedEars' Lahn schrieb:
>> I presume reading the changelog will tell.
>
> I couldn't find anything relating to this issue there.

Too bad. UTSL?

>>>> 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.
>>> My MySQL version does support them. Still, PDO's default seems to be
>>> "on" for the emulation.
>>
>> Not here; the attribute is not even supported:
>>
>> $ php -r '
>> $pdo = new PDO("mysql:host=localhost", "…", "…");
>> var_dump($pdo->getAttribute(PDO::ATTR_EMULATE_PREPARES));'
>> PHP Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not
>> support this function: driver does not support that attribute in Command
>> line code on line 3
>> PHP Stack trace:
>> PHP 1. {main}() Command line code:0
>> PHP 2. PDO->getAttribute() Command line code:3
>> bool(false)
>
> Yes, I get that error too -- which is all the more confusing, since
> otherwise the behaviour with PDO::ATTR_EMULATE_PREPARES == false is
> consistent with the assumption that prepared statements are indeed
> supported. See my reply to Jerry.

Both Jerry and you are wrong.

Prepared statements have been supported in MySQL since version 4.1 (as you
can read in the MySQL manual), and with the “pdo_mysql” extension since its
first version (as you can read in the PHP manual). Naturally, therefore
they have always been supported with the “mysql” and “mysqli” extensions
*too*, provided your MySQL client library and the MySQL server accessed with
it were recent enough.

Jerry is also confusing “mysql”, “mysqli”, and “pdo_mysql”, which are
*separate* extensions (you are using the latter). *You* are confusing the
MySQL client (library) – that is *used by* a database driver – with a
database driver (for PHP).

“pdo_mysql” is a PHP extension that provides a PDO driver (a database-
specific driver that implements the PDO interface as provided by the “pdo”
PHP extension); “mysql” and “mysqli” are PHP extensions that provide only
MySQL drivers.

“pdo_mysql” does _not_ use nor require either the “mysql” or the “mysqli”
extension. As a result, if you have “pdo_mysql” loaded (which is only
possible if you load “pdo” first), and no applications on your server that
use the mysql*_* functions/methods, you can disable the other two without
your applications that use “pdo_mysql” stopping to function. BTDT.

PHP extensions:

<<provides>>
mysql ----------------> driver --------.
(deprecated/obsolete) : <<uses>>
:
<<provides>> <<uses>> v <<accesses>>
mysqli ------------> driver <---> MySQL client -------------> MySQL server
(library)
^
<<provides>> : <<uses>>
pdo_mysql ------------> driver --------'
|
| <<implements>>
|
<<provides>> v
pdo --------------------> PDO
(data-access layer = interface)

You and I get the _warning_ above because, as you can read in the PHP
manual, “pdo_*mysql*” (at least in version 5.4.x) does not need/support that
attribute; when it detects that the MySQL client version is that old that it
does not support prepared statements, and you are using PDO::prepare(), it
will emulate them automagically.

However, as you can also read in the PHP manual, since PHP 5.4.0 MySQL
versions older than 4.1 are no longer supported by “pdo_mysql”, so there
will never be emulation of Prepared Statements with “pdo_mysql” in PHP 5.4+;
it is unnecessary.

I do not for sure know why, with PHP 5.4.x, you are getting different
results with and without setting the attribute. Maybe it has to do with the
fact that you are using a MySQL 5._0_ client library to access a MySQL 5._1_
server.

If that is not the reason, it could be either a flawed test case or a PHP
bug; if you can still reproduce it after synchronizing the MySQL client
versions with the server version, try upgrading to the latest stable version
of PHP 5.4.

BTW, MySQL 5.1.x was first released in 2005-11; it is in the
Extended/Sustaining Support phase now (IIUC, you have to pay for updates).
MySQL Server CE 5.1.41 was GA-released on 2009-11-05; the latest version is
5.1.72, GA-released on 2013-09-20.


HTH

PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(at)news(dot)demon(dot)co(dot)uk> (2004)
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183517 is a reply to message #183513] Tue, 29 October 2013 19:55 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/29/2013 2:19 PM, Thomas 'PointedEars' Lahn wrote:
> Thomas Mlynarczyk wrote:
>
>> Thomas 'PointedEars' Lahn schrieb:
>>> I presume reading the changelog will tell.
>>
>> I couldn't find anything relating to this issue there.
>
> Too bad. UTSL?
>
>>>> > 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.
>>>> My MySQL version does support them. Still, PDO's default seems to be
>>>> "on" for the emulation.
>>>
>>> Not here; the attribute is not even supported:
>>>
>>> $ php -r '
>>> $pdo = new PDO("mysql:host=localhost", "…", "…");
>>> var_dump($pdo->getAttribute(PDO::ATTR_EMULATE_PREPARES));'
>>> PHP Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not
>>> support this function: driver does not support that attribute in Command
>>> line code on line 3
>>> PHP Stack trace:
>>> PHP 1. {main}() Command line code:0
>>> PHP 2. PDO->getAttribute() Command line code:3
>>> bool(false)
>>
>> Yes, I get that error too -- which is all the more confusing, since
>> otherwise the behaviour with PDO::ATTR_EMULATE_PREPARES == false is
>> consistent with the assumption that prepared statements are indeed
>> supported. See my reply to Jerry.
>
> Both Jerry and you are wrong.
>
> Prepared statements have been supported in MySQL since version 4.1 (as you
> can read in the MySQL manual), and with the “pdo_mysql” extension since its
> first version (as you can read in the PHP manual). Naturally, therefore
> they have always been supported with the “mysql” and “mysqli” extensions
> *too*, provided your MySQL client library and the MySQL server accessed with
> it were recent enough.
>

I was not discussing the pdo_mysql extension. I was discussing the
mysql_extension - which does NOT support prepared statements. And
pdo_mysql in PHP 4.1 only emulated prepared statements; it did not
support the MySQL version of prepared statements directly.

> Jerry is also confusing “mysql”, “mysqli”, and “pdo_mysql”, which are
> *separate* ext ensions (you are using the latter). *You* are confusing the
> MySQL client (library) – that is *used by* a database driver – with a
> database driver (for PHP).
>

No, I am not. If I had meant pdo_mysql, I would have SAID pdo_mysql.

> “pdo_mysql” is a PHP extension that provides a PDO driver (a database-
> specific driver that implements the PDO interface as provided by the “pdo”
> PHP extension); “mysql” and “mysqli” are PHP extensions that provide only
> MySQL drivers.
>

Wow - you can copy and paste!

> “pdo_mysql” does _not_ use nor require either the “mysql” or the “mysqli”
> extension. As a result, if you have “pdo_mysql” loaded (which is only
> possible if you load “pdo” first), and no applications on your server that
> use the mysql*_* functions/methods, you can disable the other two without
> your applications that use “pdo_mysql” stopping to function. BTDT.
>

You mean the PDO authors wrote their own mysql client library?
Interesting that they would go to all that trouble when the MySQL client
library is readily available for use. It is also debugged and changes
as necessary with MySQL versions.

Glad I don't use PDO.

> PHP extensions:
>
> <<provides>>
> mysql ----------------> driver --------.
> (deprecated/obsolete) : <<uses>>
> :
> <<provides>> <<uses>> v <<accesses>>
> mysqli ------------> driver <---> MySQL client -------------> MySQL server
> (library)
> ^
> <<provides>> : <<uses>>
> pdo_mysql ------------> driver --------'
> |
> | <<implements>>
> |
> <<provides>> v
> pdo --------------------> PDO
> (data-access layer = interface)
>
> You and I get the _warning_ above because, as you can read in the PHP
> manual, “pdo_*mysql*” (at least in version 5.4.x) does not need/support that
> attribute; when it detects that the MySQL client version is that old that it
> does not support prepared statements, and you are using PDO::prepare(), it
> will emulate them automagically.
>
> However, as you can also read in the PHP manual, since PHP 5.4.0 MySQL
> versions older than 4.1 are no longer supported by “pdo_mysql”, so there
> will never be emulation of Prepared Statements with “pdo_mysql” in PHP 5.4+;
> it is unnecessary.
>

Who cares about old versions? Nothing in his update says he's using an
old version.

> I do not for sure know why, with PHP 5.4.x, you are getting different
> results with and without setting the attribute. Maybe it has to do with the
> fact that you are using a MySQL 5._0_ client library to access a MySQL 5._1_
> server.
>

Maybe you're not sure because you don't know anything.

> If that is not the reason, it could be either a flawed test case or a PHP
> bug; if you can still reproduce it after synchronizing the MySQL client
> versions with the server version, try upgrading to the latest stable version
> of PHP 5.4.
>
> BTW, MySQL 5.1.x was first released in 2005-11; it is in the
> Extended/Sustaining Support phase now (IIUC, you have to pay for updates).
> MySQL Server CE 5.1.41 was GA-released on 2009-11-05; the latest version is
> 5.1.72, GA-released on 2013-09-20.
>
>
> HTH
>
> PointedEars
>

Don't let the point on your head puncture your colon.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183518 is a reply to message #183517] Tue, 29 October 2013 20:06 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Jerry Stuckle wrote:

> On 10/29/2013 2:19 PM, Thomas 'PointedEars' Lahn wrote:
>> Thomas Mlynarczyk wrote:
>>> Thomas 'PointedEars' Lahn schrieb:
>>>> I presume reading the changelog will tell.
>>>
>>> I couldn't find anything relating to this issue there.
>>
>> Too bad. UTSL?
>>
>>>> >> 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.
>>>> > My MySQL version does support them. Still, PDO's default seems to be
>>>> > "on" for the emulation.
>>>>
>>>> Not here; the attribute is not even supported:
>>>>
>>>> $ php -r '
>>>> $pdo = new PDO("mysql:host=localhost", "…", "…");
>>>> var_dump($pdo->getAttribute(PDO::ATTR_EMULATE_PREPARES));'
>>>> PHP Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not
>>>> support this function: driver does not support that attribute in
>>>> Command line code on line 3
>>>> PHP Stack trace:
>>>> PHP 1. {main}() Command line code:0
>>>> PHP 2. PDO->getAttribute() Command line code:3
>>>> bool(false)
>>>
>>> Yes, I get that error too -- which is all the more confusing, since
>>> otherwise the behaviour with PDO::ATTR_EMULATE_PREPARES == false is
>>> consistent with the assumption that prepared statements are indeed
>>> supported. See my reply to Jerry.
>>
>> Both Jerry and you are wrong.
>>
>> Prepared statements have been supported in MySQL since version 4.1 (as
>> you can read in the MySQL manual), and with the “pdo_mysql” extension
>> since its
>> first version (as you can read in the PHP manual). Naturally, therefore
>> they have always been supported with the “mysql” and “mysqli” extensions
>> *too*, provided your MySQL client library and the MySQL server accessed
>> with it were recent enough.
>
> I was not discussing the pdo_mysql extension. I was discussing the
> mysql_extension - which does NOT support prepared statements. And
> pdo_mysql in PHP 4.1 only emulated prepared statements; it did not
> support the MySQL version of prepared statements directly.

You have written, quote:

| I could be wrong, but from my experience, the mysql driver has never
| supported prepared statements, while the mysqli driver has always
| supported them. This is why PDO has to emulate the prepared statements.

End of quote.

Since you are so fond of scatological references, here is one for you:
You have written bullshit. Can you at least, for once, stand by that?

>> Jerry is also confusing “mysql”, “mysqli”, and “pdo_mysql”, which are
>> *separate* ext ensions (you are using the latter). *You* are confusing
>> the MySQL client (library) – that is *used by* a database driver – with a
>> database driver (for PHP).
>
> No, I am not. If I had meant pdo_mysql, I would have SAID pdo_mysql.

You have said pdo_mysql had to emulate prepared statements because some
“mysql driver” was not capable. This is bullshit.

>> “pdo_mysql” is a PHP extension that provides a PDO driver (a database-
>> specific driver that implements the PDO interface as provided by the
>> “pdo” PHP extension); “mysql” and “mysqli” are PHP extensions that
>> provide only MySQL drivers.
>
> Wow - you can copy and paste!

I have written this from scratch, stupid.

>> “pdo_mysql” does _not_ use nor require either the “mysql” or the “mysqli”
>> extension. As a result, if you have “pdo_mysql” loaded (which is only
>> possible if you load “pdo” first), and no applications on your server
>> that use the mysql*_* functions/methods, you can disable the other two
>> without
>> your applications that use “pdo_mysql” stopping to function. BTDT.
>
> You mean the PDO authors wrote their own mysql client library?

I have said nothing of the sort. You have not even understood the
difference between a database driver and a database client library despite
it has been given to you *in graphical form*. How stupid are you anyway?


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>
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183519 is a reply to message #183511] Tue, 29 October 2013 20:09 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/29/2013 11:22 AM, Thomas Mlynarczyk wrote:
> Jerry Stuckle schrieb:
>
>> I could be wrong, but from my experience, the mysql driver has never
>> supported prepared statements, while the mysqli driver has always
>> supported them. This is why PDO has to emulate the prepared statements.
>
> This is what PDO tells me about the driver being used:
> PDO::ATTR_CLIENT_VERSION => mysqlnd 5.0.10 - 20111026
>

Ok, so you're using MySQL's driver for PHP 5.4+. That's good; it
supports everything.

>> If you disable emulation with a mysql connection, I would expect
>> errors in the execution. What is the return value from your prepare()
>> and execute() calls?
>
> Prepare() returns a PDOStatement object and execute returns true.
>

Yea, I though about the prepare() - if it didn't return a PDOStatement
object your execute() call would get a fatal exception ($stmt not an
object). But I'm surprised that the execute() call returns true.

> Everything works fine with PDO::ATTR_EMULATE_PREPARES == false (except
> for the issue with SHOW WARNINGS) and consistent with the assumption
> that prepared statements are indeed supported.
>
> $pdo->prepare( 'invalid' ) will return false; with emulated prepares it
> will return a PDOStatement object -- both as expected.
>

That part is as it should be.

> With emulated prepares,
>
> $stmt = $pdo->prepare( 'SELECT * FROM mytable LIMIT ?' );
> $stmt->execute( [ 4 ] );
>
> will give me a syntax error complaining about "LIMIT '4'", whereas with
> PDO::ATTR_EMULATE_PREPARES == false the query works fine (proving that
> the ? placeholder was indeed replaced with (int) 4 instead of (string) '4'.
>
> Greetings,
> Thomas
>

If anything, I would have expected the opposite to be true - works with
emulation but not with PDO::ATTR_EMULATE_PREPARES == false, but that's
only because I think PDO has a bit more flexibility in preparing
statements. I could be wrong, though.

Do you get a result from the 'Select 5 + "Five"'? If so, what is it?

Also, what happens if you try "Select 5 + 'Five'"? (note different quoting).

I'm beginning to think you've found a bug in the PDO extension, but I'm
not sure (yet).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183522 is a reply to message #183519] Tue, 29 October 2013 20:50 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Jerry Stuckle wrote:

> On 10/29/2013 11:22 AM, Thomas Mlynarczyk wrote:
>> Jerry Stuckle schrieb:
>>> I could be wrong, but from my experience, the mysql driver has never
>>> supported prepared statements, while the mysqli driver has always
>>> supported them. This is why PDO has to emulate the prepared statements.

AISB, that is utter nonsense. “mysql”, “mysqli”, and “pdo_mysql” (the PDO
driver for MySQL) are *different* drivers (for the *same* *third-party*
client library) and have no dependency on each other whatsoever.

Also, while the “mysql” extension does not provide a *convenience API* for
Prepared Statements (PS), and it is recommended not to use the “mysql”
extension at all, you *can* still use PSs with it; they are, after all, part
of the MySQL statement syntax:

$ php -r '
mysql_connect("localhost", "…", "…");
mysql_query("PREPARE stmt1 FROM \"SELECT SQRT(POW(?,2) + POW(?,2)) AS
hypotenuse\";");
mysql_query("SET @a = 3;");
mysql_query("SET @b = 4;");
$result = mysql_query("EXECUTE stmt1 USING @a, @b;");
var_dump(mysql_fetch_array($result));'
array(2) {
[0] =>
string(1) "5"
'hypotenuse' =>
string(1) "5"
}

(Example from
<http://dev.mysql.com/doc/refman/5.1/en/sql-syntax-prepared-statements.html>)

>> This is what PDO tells me about the driver being used:
>> PDO::ATTR_CLIENT_VERSION => mysqlnd 5.0.10 - 20111026
>
> Ok, so you're using MySQL's driver for PHP 5.4+. That's good; it
> supports everything.

You have it backwards and utterly wrong on top of that. He is _not_ using
“MySQL's driver for PHP 5.4+”. He is using PDO_MySQL – a PDO driver for
MySQL – that accesses a MySQL client library on his system (that has nothing
to do with PHP) of version 5.0.10. PDO and PDO_MySQL are available since
PHP 5.0.

Do you understand the difference?

And if he is using that older client library to access a MySQL 5._1_ server,
it is _not_ good. (Even though prepared statements should not be an issue
then – they are supported since MySQL 4.1 –, but in my experience a MySQL
version mismatch tends to cause problems.)


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183523 is a reply to message #183519] Tue, 29 October 2013 22:11 Go to previous messageGo to next message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma: 0
Senior Member
Jerry Stuckle schrieb:

> Do you get a result from the 'Select 5 + "Five"'? If so, what is it?

Yes, I get a result -- see below. I did some more testing:

$pdo = new PDO( 'mysql:...', '...', '...' );
var_dump( $pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES, false ) );
var_dump( $stmt = $pdo->prepare( 'SELECT 5 + "Five"' ) );
var_dump( $stmt->execute() );
var_dump( $stmt->fetchAll( PDO::FETCH_ASSOC ) );
var_dump( $pdo->query( 'SHOW WARNINGS' )
->fetchAll( PDO::FETCH_ASSOC ) );

Return values with PDO::ATTR_EMULATE_PREPARES = false:
setAttribute -> true
prepare -> PDOStatement
execute -> true
fetchAll -> array( '5 + "Five"' => (float) 5 )
SHOW WARNINGS -> (empty array)

Return values with PDO::ATTR_EMULATE_PREPARES = true:
setAttribute -> true
prepare -> PDOStatement
execute -> true
fetchAll -> array( '5 + "Five"' => (string) '5' )
SHOW WARNINGS -> array with warning

Results are the same with PHP 5.4.8 and PHP 5.4.21. Note the different
return types of the value 5 -- float vs. string. This surprises me a
little -- why would the setting for emulation of prepared statements
influence the *returned* data?

> Also, what happens if you try "Select 5 + 'Five'"? (note different
> quoting).

No change.

> I'm beginning to think you've found a bug in the PDO extension, but I'm
> not sure (yet).

Hm. I tested with PHP 5.4.8 and 5.4.21 and it didn't work. But it
obviously worked with PHP 5.4.15 as both Thomas Lahn's and my own test
on a different server have shown. In both cases, MySQL 5.5 is involved
whereas my local system is still on MySQL 5.1.41. This leads me to think
that it's not (or at least not entirely) a PDO issue.

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183524 is a reply to message #183523] Wed, 30 October 2013 00:12 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Thomas Mlynarczyk wrote:

> Jerry Stuckle schrieb:
>> Do you get a result from the 'Select 5 + "Five"'? If so, what is it?
>
> Yes, I get a result -- see below. I did some more testing:
>
> $pdo = new PDO( 'mysql:...', '...', '...' );
> var_dump( $pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES, false ) );
> var_dump( $stmt = $pdo->prepare( 'SELECT 5 + "Five"' ) );
> var_dump( $stmt->execute() );
> var_dump( $stmt->fetchAll( PDO::FETCH_ASSOC ) );
> var_dump( $pdo->query( 'SHOW WARNINGS' )
> ->fetchAll( PDO::FETCH_ASSOC ) );

You have a different order of fetching the result and fetching the warnings.
Please try my test cases.

> Return values with PDO::ATTR_EMULATE_PREPARES = false:
> setAttribute -> true
> prepare -> PDOStatement
> execute -> true
> fetchAll -> array( '5 + "Five"' => (float) 5 )
> SHOW WARNINGS -> (empty array)
>
> Return values with PDO::ATTR_EMULATE_PREPARES = true:
> setAttribute -> true
> prepare -> PDOStatement
> execute -> true
> fetchAll -> array( '5 + "Five"' => (string) '5' )
> SHOW WARNINGS -> array with warning
>
> Results are the same with PHP 5.4.8 and PHP 5.4.21. Note the different
> return types of the value 5 -- float vs. string. This surprises me a
> little -- why would the setting for emulation of prepared statements
> influence the *returned* data?

I have no idea.

The more important question is: Why would it matter *at* *all* in PHP 5.4.x
where by PDO_MySQL that attribute *is* *not* *supported* and *emulation*
*is* *not* *done* when using a MySQL 4.1+ client?

Something is utterly wrong with your local setup, and I assume it is at
least the MySQL version mismatch. First be clear which version of PHP,
MySQL client, and MySQL server you are using, *exactly*, and that you are
using the correct versions.

That said, why are you preparing invalid statements in the first place?


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183527 is a reply to message #183518] Wed, 30 October 2013 00:57 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/29/2013 4:06 PM, Thomas 'PointedEars' Lahn wrote:
> Jerry Stuckle wrote:
>
>> On 10/29/2013 2:19 PM, Thomas 'PointedEars' Lahn wrote:
>>> Thomas Mlynarczyk wrote:
>>>> Thomas 'PointedEars' Lahn schrieb:
>>>> > I presume reading the changelog will tell.
>>>>
>>>> I couldn't find anything relating to this issue there.
>>>
>>> Too bad. UTSL?
>>>
>>>> >>> 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.
>>>> >> My MySQL version does support them. Still, PDO's default seems to be
>>>> >> "on" for the emulation.
>>>> >
>>>> > Not here; the attribute is not even supported:
>>>> >
>>>> > $ php -r '
>>>> > $pdo = new PDO("mysql:host=localhost", "…", "…");
>>>> > var_dump($pdo->getAttribute(PDO::ATTR_EMULATE_PREPARES));'
>>>> > PHP Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not
>>>> > support this function: driver does not support that attribute in
>>>> > Command line code on line 3
>>>> > PHP Stack trace:
>>>> > PHP 1. {main}() Command line code:0
>>>> > PHP 2. PDO->getAttribute() Command line code:3
>>>> > bool(false)
>>>>
>>>> Yes, I get that error too -- which is all the more confusing, since
>>>> otherwise the behaviour with PDO::ATTR_EMULATE_PREPARES == false is
>>>> consistent with the assumption that prepared statements are indeed
>>>> supported. See my reply to Jerry.
>>>
>>> Both Jerry and you are wrong.
>>>
>>> Prepared statements have been supported in MySQL since version 4.1 (as
>>> you can read in the MySQL manual), and with the “pdo_mysql” extension
>>> since its
>>> first version (as you can read in the PHP manual). Naturally, therefore
>>> they have always been supported with the “mysql” and “mysqli” extensions
>>> *too*, provided your MySQL client library and the MySQL server accessed
>>> with it were recent enough.
>>
>> I was not discussing the pdo_mysql extension. I was discussing the
>> mysql_extension - which does NOT support prepared statements. And
>> pdo_mysql in PHP 4.1 only emulated prepared statements; it did not
>> support the MySQL version of prepared statements directly.
>
> You have written, quote:
>
> | I could be wrong, but from my experience, the mysql driver has never
> | supported prepared statements, while the mysqli driver has always
> | supported them. This is why PDO has to emulate the prepared statements.
>
> End of quote.
>
> Since you are so fond of scatological references, here is one for you:
> You have written bullshit. Can you at least, for once, stand by that?
>

Exactly. I did not say anything about PDO. But your head is too far up
your anus to understand.

>>> Jerry is also confusing “mysql”, “mysqli”, and “pdo_mysql”, which are
>>> *separate* ext ensions (you are using the latter). *You* are confusing
>>> the MySQL client (library) – that is *used by* a database driver – with a
>>> database driver (for PHP).
>>
>> No, I am not. If I had meant pdo_mysql, I would have SAID pdo_mysql.
>
> You have said pdo_mysql had to emulate prepared statements because some
> “mysql driver” was not capable. This is bullshit.
>
>>> “pdo_mysql” is a PHP extension that provides a PDO driver (a database-
>>> specific driver that implements the PDO interface as provided by the
>>> “pdo” PHP extension); “mysql” and “mysqli” are PHP extensions that
>>> provide only MySQL drivers.
>>
>> Wow - you can copy and paste!
>
> I have written this from scratch, stupid.
>

I highly doubt that. You're not that intelligent.

>>> “pdo_mysql” does _not_ use nor require either the “mysql” or the “mysqli”
>>> extension. As a result, if you have “pdo_mysql” loaded (which is only
>>> possible if you load “pdo” first), and no applications on your server
>>> that use the mysql*_* functions/methods, you can disable the other two
>>> without
>>> your applications that use “pdo_mysql” stopping to function. BTDT.
>>
>> You mean the PDO authors wrote their own mysql client library?
>
> I have said nothing of the sort. You have not even understood the
> difference between a database driver and a database client library despite
> it has been given to you *in graphical form*. How stupid are you anyway?
>
>
> PointedEars
>

Sure you did. You said quote: "pdo_mysql" does _not_ use nor require
either "mysql" or the "mysqli" extension.... : Unqote. So since it
doesn't require any of the extensions provided by MySQL, the authors
must have written their own extension.

Or are you going to admit you're full of bullshit, as always?

BTW - have you told Richard Cornford "There is no javascript"? If not,
why not?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183528 is a reply to message #183522] Wed, 30 October 2013 01:01 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/29/2013 4:50 PM, Thomas 'PointedEars' Lahn wrote:
> Jerry Stuckle wrote:
>
>> On 10/29/2013 11:22 AM, Thomas Mlynarczyk wrote:
>>> Jerry Stuckle schrieb:
>>>> I could be wrong, but from my experience, the mysql driver has never
>>>> supported prepared statements, while the mysqli driver has always
>>>> supported them. This is why PDO has to emulate the prepared statements.
>
> AISB, that is utter nonsense. “mysql”, “mysqli”, and “pdo_mysql” (the PDO
> driver for MySQL) are *different* drivers (for the *same* *third-party*
> client library) and have no dependency on each other whatsoever.
>

As usual, you have no idea what you're talking about- much less what I'm
talking about.

> Also, while the “mysql” extension does not provide a *convenience API* for
> Prepared +Statements (PS), and it is recommended not to use the “mysql”
> extension at all, you *can* still use PSs with it; they are, after all, part
> of the MySQL statement syntax:
>

Who cares what's recommended? That's not the topic.

> $ php -r '
> mysql_connect("localhost", "…", "…");
> mysql_query("PREPARE stmt1 FROM \"SELECT SQRT(POW(?,2) + POW(?,2)) AS
> hypotenuse\";");
> mysql_query("SET @a = 3;");
> mysql_query("SET @b = 4;");
> $result = mysql_query("EXECUTE stmt1 USING @a, @b;");
> var_dump(mysql_fetch_array($result));'
> array(2) {
> [0] =>
> string(1) "5"
> 'hypotenuse' =>
> string(1) "5"
> }
>
> (Example from
> <http://dev.mysql.com/doc/refman/5.1/en/sql-syntax-prepared-statements.html>)
>

I really don't care what mysql says about the code. I'm writing in PHP
and care what PHP says.

>>> This is what PDO tells me about the driver being used:
>>> PDO::ATTR_CLIENT_VERSION => mysqlnd 5.0.10 - 20111026
>>
>> Ok, so you're using MySQL's driver for PHP 5.4+. That's good; it
>> supports everything.
>
> You have it backwards and utterly wrong on top of that. He is _not_ using
> “MySQL's driver for PHP 5.4+”. He is using PDO_MySQL – a PDO driver for
> MySQL – that accesses a MySQL client library on his system (that has nothing
> to do with PHP) of version 5.0.10. PDO and PDO_MySQL are available since
> PHP 5.0.
>
> Do you understand the difference?
>

Yes, I understand the difference. But obviously you do not.

> And if he is using that older client library to access a MySQL 5._1_ server,
> it is _not_ good. (Even though prepared statements should not be an issue
> then – they are supported since MySQL 4.1 –, but in my experience a MySQL
> version mismatch tends to cause problems.)
>
>
> PointedEars
>

Please continue, Pointed Head. You're ignorance is really a great laugh.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183529 is a reply to message #183523] Wed, 30 October 2013 01:10 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/29/2013 6:11 PM, Thomas Mlynarczyk wrote:
> Jerry Stuckle schrieb:
>
>> Do you get a result from the 'Select 5 + "Five"'? If so, what is it?
>
> Yes, I get a result -- see below. I did some more testing:
>
> $pdo = new PDO( 'mysql:...', '...', '...' );
> var_dump( $pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES, false ) );
> var_dump( $stmt = $pdo->prepare( 'SELECT 5 + "Five"' ) );
> var_dump( $stmt->execute() );
> var_dump( $stmt->fetchAll( PDO::FETCH_ASSOC ) );
> var_dump( $pdo->query( 'SHOW WARNINGS' )
> ->fetchAll( PDO::FETCH_ASSOC ) );
>
> Return values with PDO::ATTR_EMULATE_PREPARES = false:
> setAttribute -> true
> prepare -> PDOStatement
> execute -> true
> fetchAll -> array( '5 + "Five"' => (float) 5 )
> SHOW WARNINGS -> (empty array)
>
> Return values with PDO::ATTR_EMULATE_PREPARES = true:
> setAttribute -> true
> prepare -> PDOStatement
> execute -> true
> fetchAll -> array( '5 + "Five"' => (string) '5' )
> SHOW WARNINGS -> array with warning
>
> Results are the same with PHP 5.4.8 and PHP 5.4.21. Note the different
> return types of the value 5 -- float vs. string. This surprises me a
> little -- why would the setting for emulation of prepared statements
> influence the *returned* data?
>
>> Also, what happens if you try "Select 5 + 'Five'"? (note different
>> quoting).
>
> No change.
>
>> I'm beginning to think you've found a bug in the PDO extension, but
>> I'm not sure (yet).
>
> Hm. I tested with PHP 5.4.8 and 5.4.21 and it didn't work. But it
> obviously worked with PHP 5.4.15 as both Thomas Lahn's and my own test
> on a different server have shown. In both cases, MySQL 5.5 is involved
> whereas my local system is still on MySQL 5.1.41. This leads me to think
> that it's not (or at least not entirely) a PDO issue.
>
> Greetings,
> Thomas
>

Thomas,

I'm not sure it isn't a PDO issue. Just because it worked with MySQL
5.5 and didn't with MySQL 5.1.41 is not entirely conclusive. Only if
there was a change in the error/warning handling between MySQL 5.1.41
and 5.5 would it be entirely MySQL.

I might recommend you check the change logs for MySQL between 5.1.41 and
5.5. Alternately, you could follow up on comp.databases.mysql and see
if there is a change. This would help determine if a change in MySQL
accounts for your difference in processing.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183530 is a reply to message #183527] Wed, 30 October 2013 01:59 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
Jerry Stuckle wrote:

> On 10/29/2013 4:06 PM, Thomas 'PointedEars' Lahn wrote:
>
>> I have said nothing of the sort. You have not even understood the
>> difference between a database driver and a database client library
>> despite
>> it has been given to you *in graphical form*. How stupid are you anyway?
>
> Sure you did. You said quote: "pdo_mysql" does _not_ use nor require
> either "mysql" or the "mysqli" extension.... : Unqote.

What is true. You can verify this by building PHP without the "Mysql"
and "Mysqli" extensions (--with-mysql --with-mysqli), but with the "PDO"
extension enabled--code using the PDO extension to access a MySQL
database will still work.

> So since it
> doesn't require any of the extensions provided by MySQL, the authors
> must have written their own extension.

A PHP extension may well use a library provided by MySQL (and PDO
actually does this when talking to a MySQL database).

--
Christoph M. Becker
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183531 is a reply to message #183530] Wed, 30 October 2013 02:04 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/29/2013 9:59 PM, Christoph Michael Becker wrote:
> Jerry Stuckle wrote:
>
>> On 10/29/2013 4:06 PM, Thomas 'PointedEars' Lahn wrote:
>>
>>> I have said nothing of the sort. You have not even understood the
>>> difference between a database driver and a database client library
>>> despite
>>> it has been given to you *in graphical form*. How stupid are you anyway?
>>
>> Sure you did. You said quote: "pdo_mysql" does _not_ use nor require
>> either "mysql" or the "mysqli" extension.... : Unqote.
>
> What is true. You can verify this by building PHP without the "Mysql"
> and "Mysqli" extensions (--with-mysql --with-mysqli), but with the "PDO"
> extension enabled--code using the PDO extension to access a MySQL
> database will still work.
>
>> So since it
>> doesn't require any of the extensions provided by MySQL, the authors
>> must have written their own extension.
>
> A PHP extension may well use a library provided by MySQL (and PDO
> actually does this when talking to a MySQL database).
>

Sure you can. But that doesn't mean you're not using the mysql or
mysqli libraries from MySQL. It only means the mysql or mysqli PHP code
is not being generated.

You don't know the difference, obviously.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183541 is a reply to message #183524] Wed, 30 October 2013 14:38 Go to previous messageGo to next message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma: 0
Senior Member
Thomas 'PointedEars' Lahn schrieb:

> You have a different order of fetching the result and fetching the warnings.
> Please try my test cases.

I just did so, but the result remains unchanged: No warning with
PDO::ATTR_EMULATE_PREPARES = false.

> The more important question is: Why would it matter *at* *all* in PHP 5.4.x
> where by PDO_MySQL that attribute *is* *not* *supported* and *emulation*
> *is* *not* *done* when using a MySQL 4.1+ client?

I had assumed emulation was the default for PDO, whether necessary or
not and you had to disable it explicitly. But if that's not the case,
the whole thing becomes even more confusing.

> Something is utterly wrong with your local setup,

I'm inclined to agree with you. My setup is a XAMPP distribution (a few
years old, yes). I had modified the Apache configuration so I could have
several different versions of PHP running as FastCGI and configure the
PHP version to use via .htaccess per project folder. Still, I don't see
how this could have messed things up in the way observed.

> and I assume it is at
> least the MySQL version mismatch. First be clear which version of PHP,
> MySQL client, and MySQL server you are using, *exactly*, and that you are
> using the correct versions.

PHP 5.4.21, CGI/FastCGI (previously 5.4.8, same result)
MySQL server: 5.1.41
MySQL client: mysqlnd 5.0.10 - 20111026 -
$Id: e707c415db32080b3752b232487a435ee0372157 $

The server is the one that came with my XAMPP installation and the PHP
distribution was downloaded yesterday.

The cleanest solution is probably a complete fresh installation, but I
can't afford any "downtime" of my dev environment at the moment.

> That said, why are you preparing invalid statements in the first place?

And how would /you/ test if warnings "work"?

Greetings,
Thomas


--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183543 is a reply to message #183529] Wed, 30 October 2013 14:51 Go to previous messageGo to next message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma: 0
Senior Member
Jerry Stuckle schrieb:

> I might recommend you check the change logs for MySQL between 5.1.41 and
> 5.5. Alternately, you could follow up on comp.databases.mysql and see
> if there is a change. This would help determine if a change in MySQL
> accounts for your difference in processing.

Thanks for the suggestion. I will take a look there when my time permits it.

Greetings,
Thomas


--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
Re: PDO - Cannot retrieve warnings with emulated prepares disabled [message #183549 is a reply to message #183501] Wed, 30 October 2013 20:09 Go to previous message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma: 0
Senior Member
I have done some more testing.
PHP 5.4.13, MySQL 5.1.66 -> no warning
PHP 5.4.15, MySQL 5.5.31 -> warning works

But I've also noticed that the two installations above don't seem to use
mysqlnd. There's no mysqlnd section in phpinfo() and the pdo_mysql
section has the client API version identical to the MySQL version,
whereas in installations with mysqlnd the client API version is listed
as mysqlnd 5.0.10 - 20111026. (Unless this is somehow a consequence of
the fact that the two installations above use the Apache module while
the "mysqlnd installations" that I checked both run PHP as CGI/FastCGI.)

There is a correlated side effect: the non-mysqlnd installations always
return data as strings, whereas the mysqlnd installations return data
with their real type (int, float or string) if emulated prepares are off.

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: splitting list into columns
Next Topic: reading files with accents in the filename from PHP
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 08:26:57 GMT 2024

Total time taken to generate the page: 0.02689 seconds