user3062123 user3062123 - 1 year ago 342
SQL Question

Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in Undefined class constant (PHP 5.5.3)

I have a config file that connects to a remote database, however i keep receiving an error that i don't know how to fix. In the earlier versions it was meant to be a bug but i assumed it would have been fixed by 5.5.3.

ini_set('display_errors', 'on');

$host = "localhost";
$dbname = "registration";
$username = "databaseEditor";
$password = "yolo10";

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

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



header('Content-Type: text/html; charset=utf-8');

echo "File works";

I keep receiving the error
"Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'"
. I have tried to use 1002 instead of 'MYSQL_ATTR_INIT_COMMAND' but then i end up with the error
"syntax error, unexpected '1002' (T_LNUMBER)"
instead and i have also have installed the newest php-mysql extension.

Answer Source

Try editing your php.ini:

On a windows server you can add the following lines in your php.ini


On a Linux server you can compile php with the following option --with-pdo-mysql

In your php.ini, add the following lines
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download