D_____________ D_____________ - 1 month ago 4x
PHP Question

undefined class constant 'mysql_attr_init_command' in MAMP using php 5.4.4

I have seen the other SO questions dealing with the bug in php 5.3 and have php_pdo_mysql enable in the php.ini file located in MAMP/conf/php5.4.4. When I look at the phpInfo, under PDO it only has the sqlite driver enabled. If anyone has any suggestions on how to troubleshoot this further it would be greatly appreciated.

This is the line in question:

$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');

I'm including some additional info as I think it applies to the solutions I've tried so far

$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
catch(PDOException $ex)
die("Failed to connect to the database: " . $ex->getMessage());

I tried replacing all the variable parameters of the PDO object with string values ie. {$host} becomes 'localhost' etc. and got the error message in the catch block with $ex->getMessage() being 'could not find driver'


Check out this DSN:

$dsn = 'mysql:dbname=testdb;host=;charset=utf8';

Instead of MySQL attr init command.