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
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.
I would like to generally answer that NO it's not safe to just remove php-mysql and install php-mysqlnd, especially if you're not "a server guy". Because once I removed php-mysql I removed phpmyadmin along with it and that was quite a disaster.
I ended up (with help of Rackspace server guys) with upgrading my PHP to 5.4 (can't go to 5.5 yet until I convert all my code to use mysqli) and then manually forcing the install of php54-mysqlnd-5.4.17-1.ius.el6.x86_64 (http://dev.mysql.com/downloads/connector/php-mysqlnd/), because of the error while trying to do it "the normal way" Error: php54-mysql conflicts with php54-mysqlnd-5.4.17-1.ius.el6.x86_64. Hope this helps someone.
Also be aware of mysqlnd returning number as numbers, while libmysqlclient (php-mysql) returns all types as string.
So if you use ===, it may give unexpected behavior.
Had a case with mysqlnd in the dev-envirement, and libmysqlclient in the production-envirement, got a few bugs where I compared a string value and an integer value, but on the dev server they was both integers.
Related
I'm installing a template on Php 7.0 / MySQL 5.5 that needs the Mysql extension installed.
This is on Ubuntu 14.04, MySql version 5.5, PHP Version 7.0.7-4+deb.sury.org~trusty+1
Currently, despite having installed mysql-server and mysql-client and php7.0-mysql -- this pre-requisite installation code is still returning false:
if(!extension_loaded('mysql')){$error = TRUE; echo " Mysql PHP extension missing!";}else{echo " Mysql PHP extension loaded!";}
mysqli is installed successfully, but for some reason Php is not seeing the mysql extension and therefore I cannot proceed with my installation.
The same thing is true on a phpinfo() check -- no MySQL module to be found, instead there is pdo_mysql, mysqlnd, and mysqi.. When I check the active php ini file (in fpm folder) I don't see anything obvious in there either.
What do I need to install or enable to get the Mysql extension showing up??
The mysql extension is deprecated. See http://php.net/manual/en/mysql.php
Your options are:
1) Switch to mysqli or PDO. Ideally PDO, since it supports prepared queries and is becoming the extension of choice for the PHP community.
2) If you have a lot of legacy code, then you're better off remaining with PHP 5.
Sorry, but mysql extension is not under the development. It deprecated since PHP 5.5 and was removed in PHP 7.0.
The fathers of mysql could just improve mysql to the new state but they decided to create MySQL Improved or mysqli.
The new things in mysqli that mysql didn't have:
Support for asynchronous queries.
Stored procedures
Parameterized queries
Transactions
Better security model.
Probable few more, but I cannot recall all now.
My default php.ini file lists both extensions (installed via brew), and I sometimes see different variations on Linux (AMZN vs Centos) with the _pdo_ bit. What is the difference?
Update: I was getting errors saying pg_connect not found and this seems to be part of the non-PDO version. To get this installed on Mac via brew, I needed to add support by running brew reinstall php56 --with-postgresql
PDO is short for PHP Data Objects and is an abstraction that can be mapped on to a lot of different databases. This means you can move between things like MySQL, PGSQL and SQLite very easily. The PDO module enables the functions you see here for PGSQL.
The non-PDO module is specific to Postgres and will enable this set of non-standardized functions that will only work with Postgres databases.
The PDO extension can connect to different database management systems with the same syntax, as long as there's a driver for the system you want to use. The PostgreSQL extension can only connecto to PostgreSQL.
What you see is the PostgreSQL extension and the PDO driver for PostgreSQL.
We have developed a web-application that runs on various server environments (> PHP 5.3), which currently uses the "deprecated" mysql extension to connect to mysql. Since PHP 7 however, it seems mysql is not installed by default, only the newer mysqli extension.
So we would like to convert our scripts to use mysqli, but we are concerned if the mysqli extension is not installed on "older" servers. So the question basically goes: Is mysqli generally ubiquitous since PHP version 5.3? Does anyone know from what version of PHP mysqli comes installed as default?
If some of our users are on hosts without mysqli, we would need to create a wrapper script, that detects if mysqli is available, and fall back to mysql if not.
Anyone with knowledge care to shine some light on this? Thanks
MySQLi was added with PHP 5.0
You can check if mysqli is installed by doing this:
if ( function_exists('mysqli_connect') )
// mysqli is installed
My php installed with pdo_mysql, without mysqli/mysql. When I use phpMyAdmin, it showed
"The mysqli|mysql extension is missing".
I tried many times to install mysqli/mysql but failed, and I don't want to re-compile php. So I gave up and chose another mysql web tool Adminer which can use pdo_mysql.
Question : Is it possible that phpMyAdmin use pdo_mysql to access mysql db? I think it should be not hard ,since another tool can.
This information is not immediately available in the online documentation, but the FAQ has it:
phpMyAdmin can connect to your MySQL server using PHP’s classic MySQL extension as well as the improved MySQL extension (MySQLi)
The phrasing is more explicit in their Wiki:
[Requirements]
(...)
Either the mysql or mysqli extensions
(...)
So the answer is: not by default, but contributions are welcome :)
I am trying to use the new development server in PHP 5.4. It runs phpinfo() just fine but on my site code and also phpMyAdmin.php they are throwing the following error:
Call to undefined function mysql_connect()
They are running through localhost:8000
php -m is showing that mysqlnd is loaded but that maybe not enough.
The OS is Windows 7
Any thoughts?
mysqlnd is the library that can be used since PHP 5.3, instead of libmysql, by 3 PHP extensions :
mysql, which provides the mysql_* functions,
mysqli, which provides the mysqli_* functons,
and pdo_mysql, which allows one to use PDO with a MySQL database.
mysqlnd by itself doesn't export any function you can use from your PHP scripts : it only provides MySQL connectivity to those 3 extensions -- which are the ones that export functions you can use.
If you want to use the mysql_* functions, you have to make sure that the mysql extension is enabled, with something that whould look like this in one of the .ini files parsed by PHP :
extension=mysql.dll
As a sidenote : the mysql_* functions should not be used anymore, especially for new projects : the mysql extension is old, and doesn't allow one to use recent (well, not that recent anymore, actually) features of MySQL.
Instead, you should be using mysqli or PDO.
It's because register_globals is no longer included as of PHP5.4, in earlier versions it was deprecated and you could force it on. The reason is because it would leave huge security gaps for hackers to exploit.
try install missing mysql module
sudo apt install php-mysqli
check if extension=mysql.so is set in php.ini after installation