我取消注释了我的php.ini文件中的行extension=php_pdo_mysql.dll
extension=php_pdo.dll
,但我仍然收到错误
Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'
以前的答案都不适合我,我该怎么办?
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
try
{ $cnx = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password,$options);
}
catch(PDOException $ex)
{ die("Failed to connect to the database: " . $ex->getMessage());
}
答案 0 :(得分:0)
尝试一次..!
try
{
$cnx = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
}
catch(PDOException $ex)
{ die("Failed to connect to the database: " . $ex->getMessage());
}
//需要更多
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass, array(
PDO::ATTR_PERSISTENT => true
));
Rrefer一次: