$db = new PDO(\'mysql:dbname=xnews;host=localhost;port=\' . $LOCAL_DB_PORT,
$LOCAL_DB_USER,
$LOCAL_DB_PASS,
array(PDO::MYSQL_ATTR_IN
I got this error this morning, I just did a fresh install of Fedora 14 and was trying to get my local projects back online. I was missing php-mysql, I installed it via yum and the error is now gone.
For Centos I was missing php-mysql library:
yum install php-mysql
service httpd restart
There is no need to enable any extension in php.ini, it is loaded by default.
This is due to a PHP 5.3.0 bug on Windows where MYSQL_ATTR_INIT_COMMAND is not available. The PHP bug report is:
http://bugs.php.net/bug.php?id=47224
If you are experiencing this, please update your WAMP product to a version that uses PHP 5.3.1 or later version.
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.
Using the int value 1002
seems to work for PHP 5.3.0:
public static function createDB() {
$dbHost="localhost";
$dbName="project";
$dbUser="admin";
$dbPassword="whatever";
$dbOptions=array(1002 => 'SET NAMES utf8',);
return new DB($dbHost, $dbName, $dbUser, $dbPassword,$dbOptions);
}
function createConnexion() {
return new PDO(
"mysql:host=$this->dbHost;dbname=$this->dbName",
$this->dbUser,
$this->dbPassword,
$this->dbOptions);
}