Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' with pdo

后端 未结 11 2136
暖寄归人
暖寄归人 2020-11-29 07:27
$db = new PDO(\'mysql:dbname=xnews;host=localhost;port=\' . $LOCAL_DB_PORT, 
          $LOCAL_DB_USER, 
          $LOCAL_DB_PASS, 
          array(PDO::MYSQL_ATTR_IN         


        
11条回答
  •  醉酒成梦
    2020-11-29 07:59

    I just tried with PHP 5.2, and that constant seems to exists :

    var_dump(PDO::MYSQL_ATTR_INIT_COMMAND);
    

    Gives me :

    int 1002
    


    But it seems there is a bug in PHP 5.3, that causes this constant to not exists anymore -- or, at least, not when the mysqlnd driver is used (and it's the one that's configured by default)

    I suppose a temporary solution, as suggested on this bug report, could be to directly use the integer 1002 value, instead of the contant...

    But note that you should go back to using the constant as soon as possible -- as this makes the code easier to understand.

提交回复
热议问题