分类: Linux
LNMP环境“Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'”解决办法

错误问题日志:

2017/05/20 23:44:20 [error] 12171#0: *5 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in /data/www/zg/core/library/dbpdo.class.php on line 15" while reading response header from upstream

Nginx前台直接500了,主要是php没有安装pdo,而程序里面链接用的是pdo_mysql,解决方法如下:
下载并安装PDO_MYSQL

cd /tmp
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
/usr/local/php5/bin/phpize
./configure –with-pdo-mysql=/usr/local/mysql
make
make install

如果出现如下报错:

In file included from /data/PDO_MYSQL-1.0.2/pdo_mysql.c:31:
/tmp/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:25:19: error: mysql.h: No such file or directory
In file included from /data/PDO_MYSQL-1.0.2/pdo_mysql.c:31:
/tmp/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:36: error: expected specifier-qualifier-list before ‘MYSQL’
/tmp/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:48: error: expected specifier-qualifier-list before ‘MYSQL_FIELD’
/tmp/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:53: error: expected specifier-qualifier-list before ‘MYSQL_RES’
make: *** [pdo_mysql.lo] Error 1

是因为在编译时需要mysql的头文件,而默认搜索路径找不到头文件的位置,所以才出现这个问题,需将 /usr/local/mysql/include/mysql/ 目录下的mysql头文件链接到 /usr/local/include/ 的目录下:直接做个软连接即可

ln -s /usr/local/mysql/include/mysql/* /usr/local/include/

安装完成以后,在php.ini里面添加

extension=pdo_mysql.so

最后重启

/etc/init.d/php-fpm restart

服务即可;
pdo.png


相关博文:

发表新评论