Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60935 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60712 invoked from network); 22 Jun 2012 10:25:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jun 2012 10:25:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=johannes.schlueter@oracle.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=johannes.schlueter@oracle.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain oracle.com designates 148.87.113.117 as permitted sender) X-PHP-List-Original-Sender: johannes.schlueter@oracle.com X-Host-Fingerprint: 148.87.113.117 rcsinet15.oracle.com Received: from [148.87.113.117] ([148.87.113.117:44308] helo=rcsinet15.oracle.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/CA-21324-C0844EF4 for ; Fri, 22 Jun 2012 06:25:17 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q5MAPCag029889 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 22 Jun 2012 10:25:13 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q5MAPBrH019831 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 22 Jun 2012 10:25:11 GMT Received: from abhmt120.oracle.com (abhmt120.oracle.com [141.146.116.72]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q5MAPANp028724; Fri, 22 Jun 2012 05:25:10 -0500 Received: from [192.168.2.230] (/88.217.76.1) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 22 Jun 2012 03:25:10 -0700 To: Anthony Ferrara Cc: Ulf Wendel , internals@lists.php.net In-Reply-To: References: <4FDB5604.5000704@oracle.com> <4FDB62C2.6090702@oracle.com> <4FDC3396.10406@phpdoc.de> <4FE0F301.70808@oracle.com> <4FE2C5D7.2040606@phpdoc.de> Content-Type: text/plain; charset="UTF-8" Organization: Oracle Corporation Date: Fri, 22 Jun 2012 12:25:07 +0200 Message-ID: <1340360707.1719.61.camel@guybrush> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: quoted-printable X-Source-IP: acsinet22.oracle.com [141.146.126.238] Subject: Re: [PHP-DEV] [PATCH - PR] Disable ATTR_EMULATE_PREPARES by default for PDO_Mysql From: johannes.schlueter@oracle.com (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Thu, 2012-06-21 at 22:35 -0400, Anthony Ferrara wrote: > Actually, the more I think about it, this would result in an > inadvertent API change. Right now, if you have a SQL syntax error, the > error would be thrown by ->execute(). But with this change, the error > would be thrown by ->prepare(). So code that currently wraps execute() > but not prepare() with a try{}catch(){} would start failing. >=20 > Is this a show stopper? Or is restoring the "proper" execution path worth= it? >=20 > From what I can see in the few open source drivers I looked at, it > won't be an issue (Drupal, Doctrine, Zend, Lithium, etc)... Well, one can easily argue that an error during prepare is the correct behavior, so this could actually be seen as a bug fix. The interesting question is whether PDO's emulation allows placeholders in places where the MySQL server doesn't in old servers (5.0?) a case was SELECT * FROM t LIMIT ? which was invalid in MySQL but valid with PDO when binding as integer. This would be a broken feature. On some quick(!) tests I didn't come up with a case where this was relevant. On a related note, as I wrote in a previous mail (which Ulf mentioned) there are still statements which can't be prepared in MySQL. One example is ALTER DATABASE. The MySQL documentation unfortunately has only a positive list[1] which makes it a it hard to find the missing ones ... anyways, PDO then tries to fallback to emulation, but there seems to be a bug: setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $p->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); var_dump($p->query("ALTER DATABASE foo CHARACTER SET =3D utf8")); ?> Fatal error: Uncaught exception 'PDOException' with message '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.' =20 I will try to look into the bug (unless anybody else is faster) but it shows that that area needs more testing, too. If you're still running 5.1 the list of prepareable statements is much shorter[2]. 5.1 currently is still quite common as many distributions bundle it, but I assume it's no big deal for php-master as it will take sometime till php-master is released and reaches the people and by then most are hopefully on 5.5 or even 5.6. johannes [1] http://dev.mysql.com/doc/refman/5.5/en/sql-syntax-prepared-statements.h= tml [2] http://dev.mysql.com/doc/refman/5.1/en/sql-syntax-prepared-statements.h= tml --=20 Johannes Schl=C3=BCter, MySQL Engineering, ORACLE Deutschland B.V. & Co KG