tags:

views:

975

answers:

3
$db = new PDO('mysql:dbname=xnews;host=localhost;port=' . $LOCAL_DB_PORT, 
          $LOCAL_DB_USER, 
          $LOCAL_DB_PASS, 
          array(PDO::MYSQL_ATTR_INIT_COMMAND =>  "SET NAMES 'UTF8'")
      );

reports:

Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'

Is it renamed?

A: 

It appears to only be availabe using the mysqlnd driver.
Try replacing it with the integer it represents; 1002, if I am not mistaken.

Atli
+1  A: 

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.

Pascal MARTIN
A: 

You could try replacing it with 1002 or issuing your initialization query right after opening a connection.

andr