简体   繁体   中英

How to enable mysqli with PHP 7?

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(); ?> <?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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM