Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'

当运行一个PHP项目时,遇到报错:Undefined class constant ‘MYSQL_ATTR_INIT_COMMAND’

第一步:需要去php.ini中开启extension=pdo_mysql,就是把它前面的分号去掉。
不知道php.ini在哪里的同学,可以在一个PHP文件中输出phpinfo(),然后查看这个页面:
我的index.php文件内容如下:

<?php
phpinfo();
?>

页面如下:可以看到php.ini的路径在/ect/php/7.2/fpm/下面
在这里插入图片描述
然后去php.ini开启pdo_mysql扩展(去掉前面的分号)。
然后重启PHP、Nginx。

service php7.2-fpm restart
service nginx restart

如果此时还没解决问题,有可能是没有安装MySQL扩展插件,继续看第二步。


第二步:安装php-mysql

apt-get install php7.2-mysql

然后重启PHP、Nginx。

service php7.2-fpm restart
service nginx restart

猜你喜欢

转载自blog.csdn.net/jal517486222/article/details/102625480