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
Related
I have the latest version of Apache (Apache 2.4), latest version of PHP (PHP7), and latest version of MySQL (not sure the version but I have WorkBench version 6.3). In the past, when I checked if my PHP was working by this line of code <?php phpinfo(); ?> it would show that I have MySQL / mysqli installed and ready to go. But with PHP7 it shows mysqlnd.
I try using mysqli commands to check if I can connect to my database by mysqli_ping() and I also tried connecting to the database using server, user, pass. I keep getting errors such as Class mysqli not found. Or Call to undefined function mysqli_ping(). I've tried searching the net for some answers and All I could find was that I need to install MySQL (but a few sites said it was deprecated).
Am I able to get mysqli for PHP7? Or do I use mysqlnd? What is mysqlnd? Is it a new version of MySQL/mysqli?
Update 2020
For Windows 10 users I strongly recommend windows subsystem for linux (WSL 2) and setup your server there.
If you need php and mysql access in windows environment, then the fastest way is to install Wampserver. If you also need access to php through console then add php location (like C:\wamp64\bin\php\php7.4.11) to environment variables.
If that doesn't suit you and you need full setup always enabled on your system then follow install with choco.
To work properly with apache and load all needed extensions (including php_mysqli) you need ThreadSafe version of PHP, so make sure to download correct version or if you use Chocolatey to manage your windows applications, then just install php with this command:
choco install php --package-parameters='"/ThreadSafe "'.
This will install php in C:\tools\php72 directory, but you can overwrite it with another parameter:
choco install php --package-parameters='"/ThreadSafe ""/InstallDir:C:\PHP"""'.
The mysqlnd extension is part of PHP. It was developed as an alternative to bundling the libmysqlclient, because that library had license conditions that made it awkward to bundle with PHP.
You won't use mysqlnd directly. It's an internal library that is used by mysqli and pdo_mysql as a means to communicate with the MySQL Server.
As for mysqli, yes, it's available for PHP 7. I don't use Windows, but apparently not all extensions are enabled by default.
You probably need to edit your php.ini and uncomment the line
extension=ext_mysqli.dll
or whatever it is for that extension. It might already be in the file, but commented out. So go take a look and see.
Check if your system path environmental variable includes the PHP installation directory. That worked for me on with PHP 7.1 / Apache 2.4 / Windows Server 2016.
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.
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
I am building an application which includes prepared mysqli statements.
I use Object oriented PHP.
The day before yesterday everything was working great.
Yesterday I updated my Ubuntu machine (which I currently use as web server).
Today I was trying again and poof! there was an error.
"call to undefined method mysqli_stmt::get_result()"
So I went to the internet and found out that get_result needs the mysqlnd library.
So I used the following to check if the library is included:
if (extension_loaded('mysqlnd')) {
echo 'extension mysqlnd is loaded'; //works
}else{
echo 'extension is not loading';
}
And indeed I got the message that the extension is not loading. What I want to do now is try to load the library, but how do I do that?
The best I could found was this:
http://php.net/manual/en/mysqlnd.install.php
But even with some trial and error I can't get this to work.
Question: How do I load the mysqlnd library?
You cannot load mysqlnd library. This is a special PHP extension that cannot be enabled/disabled by PHP ini config and the extension doesn't expose any functionality by itself.
Mysqlnd is a client library for connecting to MySQL servers. It's actually a C library implemented as a PHP extension. It means that you can use it when writing another PHP extension in C, e.g. mysqli, PDO_MySQL or php_mysql.
The only way it can be enabled/disabled is during the compilation of PHP source code via one of the compilation flags for either mysqli or PDO_MySQL extensions. You need to recompile your PHP distributable with the appropriate flag (the flag is set to On by default, so if you are missing some functions in mysqli it means your PHP was compiled with libmysql instead).
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.