Skip to content
Home » Web » PHP » How to Resolve Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'

How to Resolve Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'

MYSQL_ATTR_INIT_COMMAND

A PHP error found in the web page below:

Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in /var/www/html/xxx.php on line 89

In the first place, I thought my php version is too old to be able to accept this constant, but it's not.

[root@test ~]# php -v
PHP 5.5.18 (cli) (built: Oct 16 2014 12:21:51)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

php-mysqlnd

So I turned to focus on missing packages. Finally, I found that it was the absence of MySQL driver php-mysqlnd which is related to MYSQL_ATTR_INIT_COMMAND. So I installed it by the following command.

[root@test ~]# yum -y --enablerepo=remi,remi-php55 install php-mysqlnd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.isu.edu.tw
 * epel: mirror01.idc.hinet.net
 * extras: ftp.isu.edu.tw
 * remi: remi.kazukioishi.net
 * remi-php55: remi.kazukioishi.net
 * updates: ftp.isu.edu.tw
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php-mysqlnd.x86_64 0:5.5.18-1.el6.remi will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch         Version                  Repository        Size
================================================================================
Installing:
 php-mysqlnd       x86_64       5.5.18-1.el6.remi        remi-php55       3.6 M

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 3.6 M
Installed size: 4.9 M
Downloading Packages:
php-mysqlnd-5.5.18-1.el6.remi.x86_64.rpm                 | 3.6 MB     00:13
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : php-mysqlnd-5.5.18-1.el6.remi.x86_64                         1/1
  Verifying  : php-mysqlnd-5.5.18-1.el6.remi.x86_64                         1/1

Installed:
  php-mysqlnd.x86_64 0:5.5.18-1.el6.remi

Complete!

If you don't know about remi repository, please refer to my post: How to Install Newest LAMP on CentOS 7 Minimal (3/3) - PHP

Don't forget to restart httpd, otherwise, the newly installed package does not take effect until the service restarted.

[root@test ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

This solves the problem on MYSQL_ATTR_INIT_COMMAND.

Leave a Reply

Your email address will not be published. Required fields are marked *