未定义类常量中的未定义类常量 'MYSQL_ATTR_INIT_COMMAND' (PHP 5.5.3) [英] Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in Undefined class constant (PHP 5.5.3)
问题描述
我有一个连接到远程数据库的配置文件,但是我不断收到一个我不知道如何修复的错误.在早期版本中,它本来是一个错误,但我认为它会在 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.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
$host = "localhost";
$dbname = "registration";
$username = "databaseEditor";
$password = "yolo10";
// 1002 = MYSQL_ATTR_INIT_COMMAND
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
try
{
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username$
}
catch(PDOException $ex)
{
die("Failed to connect to the database: " . $ex->getMessage());
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
header('Content-Type: text/html; charset=utf-8');
echo "File works";
?>
我一直收到错误未定义的类常量'MYSQL_ATTR_INIT_COMMAND'"
.我曾尝试使用 1002 而不是 'MYSQL_ATTR_INIT_COMMAND' 但后来我得到了错误语法错误,意外的 '1002' (T_LNUMBER)"
而我也安装了最新的 php-mysql 扩展.
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.
推荐答案
尝试编辑您的 php.ini:
Try editing your php.ini:
在 Windows 服务器上,您可以在 php.ini 中添加以下几行
On a windows server you can add the following lines in your php.ini
extension=php_pdo.dll
extension=php_pdo_mysql.dll
在 Linux 服务器上,您可以使用以下选项 --with-pdo-mysql 编译 php
On a Linux server you can compile php with the following option --with-pdo-mysql
在你的 php.ini 中,添加以下几行
In your php.ini, add the following lines
extension=pdo.so
extension=pdo_mysql.so
这篇关于未定义类常量中的未定义类常量 'MYSQL_ATTR_INIT_COMMAND' (PHP 5.5.3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!