Will installing mysqlnd break existing code in PHP which uses mysql?

Nikola picture Nikola · Aug 21, 2013 · Viewed 10k times · Source

I'm moving my code from using mysql in PHP to mysqli. In order to get the mysqli get_result() function to work I need to install mysqlnd as said here on SO. This involves removing the existing php-mysql extension, and now I just want to make sure (those of you who did this) that once I remove the mysql with:

yum remove php-mysql

and install mysqlnd with:

yum install php-mysqlnd

the other code (there's a lot of existing codebase) that uses mysql will still work?

My PHP Version is 5.3.27

Answer

Arash Mousavi picture Arash Mousavi · Aug 21, 2013

With both of php-mysql and php-mysqlnd you have mysql, mysqli and PDO drivers all together. If you just need mysqli driver you already have it with php-mysql.

However if you want migrate to MySQL native driver According to documentation you must pay attention to these:

--The new mysqlnd library necessitates the use of MySQL 4.1's newer 41-byte password format. Continued use of the old 16-byte passwords will cause mysql_connect() and similar functions to emit the error, "mysqlnd cannot connect to MySQL 4.1+ using old authentication." The

--new mysqlnd library does not read mysql configuration files (my.cnf/my.ini), as the older libmysqlclient library does. If your code relies on settings in the configuration file, you can load it explicitly with the mysqli_options() function. Note that this means the PDO specific constants PDO::MYSQL_ATTR_READ_DEFAULT_FILE and PDO::MYSQL_ATTR_READ_DEFAULT_GROUP are not defined if MySQL support in PDO is compiled with mysqlnd.

Generally you don't have any problem to migrate from MySQL driver to MySQL native driver. Also it recommended to use php-mysqlnd instead of php-mysql.