Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11628

Re: PDO - Cannot retrieve warnings with emulated prepares disabled

Message-ID <2131967.hbSm1AV4dr@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-10-29 19:19 +0100
Subject Re: PDO - Cannot retrieve warnings with emulated prepares disabled
Newsgroups comp.lang.php
References <l4mohq$9ea$1@news.albasani.net> <12356089.gSGYd4PIy3@PointedEars.de> <l4o9qm$1u3$1@news.albasani.net> <2185476.vkglFbDy2O@PointedEars.de> <l4ok2h$n2u$1@news.albasani.net>

Show all headers | View raw


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@news.demon.co.uk> (2004)

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

PDO - Cannot retrieve warnings with emulated prepares disabled Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-10-28 23:30 +0100
  Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-29 13:10 +0100
    Re: PDO - Cannot retrieve warnings with emulated prepares disabled Tim Streater <timstreater@greenbee.net> - 2013-10-29 12:23 +0000
    Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-10-29 13:31 +0100
      Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-29 13:47 +0100
        Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-10-29 16:26 +0100
          Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-29 19:19 +0100
            Re: PDO - Cannot retrieve warnings with emulated prepares disabled Jerry Stuckle <jstucklex@attglobal.net> - 2013-10-29 15:55 -0400
              Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-29 21:06 +0100
                Re: PDO - Cannot retrieve warnings with emulated prepares disabled Jerry Stuckle <jstucklex@attglobal.net> - 2013-10-29 20:57 -0400
                Re: PDO - Cannot retrieve warnings with emulated prepares disabled Christoph Michael Becker <cmbecker69@arcor.de> - 2013-10-30 02:59 +0100
                Re: PDO - Cannot retrieve warnings with emulated prepares disabled Jerry Stuckle <jstucklex@attglobal.net> - 2013-10-29 22:04 -0400
      Re: PDO - Cannot retrieve warnings with emulated prepares disabled Jerry Stuckle <jstucklex@attglobal.net> - 2013-10-29 08:58 -0400
        Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-10-29 16:22 +0100
          Re: PDO - Cannot retrieve warnings with emulated prepares disabled Jerry Stuckle <jstucklex@attglobal.net> - 2013-10-29 16:09 -0400
            Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-29 21:50 +0100
              Re: PDO - Cannot retrieve warnings with emulated prepares disabled Jerry Stuckle <jstucklex@attglobal.net> - 2013-10-29 21:01 -0400
            Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-10-29 23:11 +0100
              Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-30 01:12 +0100
                Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-10-30 15:38 +0100
              Re: PDO - Cannot retrieve warnings with emulated prepares disabled Jerry Stuckle <jstucklex@attglobal.net> - 2013-10-29 21:10 -0400
                Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-10-30 15:51 +0100
  Re: PDO - Cannot retrieve warnings with emulated prepares disabled Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-10-30 21:09 +0100

csiph-web