Home > Article > Backend Development > What should I do if php cannot connect to mysqli?
Solution for php unable to connect to mysqli: 1. Open the "php.ini" file; 2. Find "mysqli.reconnect"; 3. Change "mysqli.reconnect = OFF" to "mysqli.reconnect = on".
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
What should I do if php cannot connect to mysqli?
PHP connects to MySql to solve the problem of "Uncaught Error: Class 'mysqli' not found"
My PHP is 7.4, but the mysql extension seems to be before 5, so I You can only use the mysqli extension to operate the database
I read dozens of answers. My mistake is that the phpinfo() page only has one mysqlnd and no mysqli, so the web page will report an error "Uncaught Error: Class 'mysqli' not found "
In php.ini
extension_dir = "ext" has also been changed to an absolute path, and the; in front of ;extension=php_mysqli.dll has also been removed. Still not working
Finally found the following paragraph
[MySQLi] ; Maximum number of persistent links. -1 means no limit. ; http://php.net/mysqli.max-persistent mysqli.max_persistent = -1 ; Allow accessing, from PHP’s perspective, local files with LOAD DATA statements ; http://php.net/mysqli.allow_local_infile ;mysqli.allow_local_infile = On ; Allow or prevent persistent links. ; http://php.net/mysqli.allow-persistent mysqli.allow_persistent = On ; Maximum number of links. -1 means no limit. ; http://php.net/mysqli.max-links mysqli.max_links = -1 ; Default port number for mysqli_connect(). If unset, mysqli_connect() will use ; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the ; compile-time value defined MYSQL_PORT (in that order). Win32 will only look ; at MYSQL_PORT. ; http://php.net/mysqli.default-port mysqli.default_port = 3306 ; Default socket name for local MySQL connects. If empty, uses the built-in ; MySQL defaults. ; http://php.net/mysqli.default-socket mysqli.default_socket = ; Default host for mysqli_connect() (doesn’t apply in safe mode). ; http://php.net/mysqli.default-host mysqli.default_host = ; Default user for mysqli_connect() (doesn’t apply in safe mode). ; http://php.net/mysqli.default-user mysqli.default_user = ; Default password for mysqli_connect() (doesn’t apply in safe mode). ; Note that this is generally a bad idea to store passwords in this file. ; Any user with PHP access can run 'echo get_cfg_var(“mysqli.default_pw”) ; and reveal this password! And of course, any users with read access to this ; file will be able to reveal the password as well. ; http://php.net/mysqli.default-pw mysqli.default_pw = ; Allow or prevent reconnect mysqli.reconnect = OFF
just change mysqli.reconnect = OFF
to mysqli.reconnect = on
and it will be fine. Speechless, if anyone has the same situation as me, you can change this
Recommended study: "PHP Video Tutorial"
The above is the detailed content of What should I do if php cannot connect to mysqli?. For more information, please follow other related articles on the PHP Chinese website!