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.
> 
> Is this a show stopper? Or is restoring the "proper" execution path worth it?
> 
> 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:

    <?php
    $p = new PDO("mysql:host=localhost","root");
    $p->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    $p->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    var_dump($p->query("ALTER DATABASE foo CHARACTER SET = 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.'
        
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.html
[2] http://dev.mysql.com/doc/refman/5.1/en/sql-syntax-prepared-statements.html

-- 
Johannes Schlüter, MySQL Engineering, ORACLE Deutschland B.V. & Co KG


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to