Solve the error when php connects to mysql database: Fatal error: Class ‘mysqli’ not found in [Update 23.12.12]

During the process of using php to connect to mysql, an error occurredFatal error: Uncaught Error: Class "mysqli" not found in ’s question

solution

This error usually means that the MySQL extension is missing or not enabled in yourPHP code.

Let’s first confirm that the MySQL extension has been installed in the PHP environment. Check whether there is the file php_mysqli.dll in your php path. If it proves that your php canconnect to mysql.

Find the php.ini file, open and search for extension=mysqli, and remove the semicolon in front of it

4. Search for extension=mysqli and remove the ; in front of it (PS. There are two search results for extension=mysqli, pay attention to the modified position)

5. Search extension_dir, find the line extension_dir = "ext", and remove the ";" in front of it (PS. Note that extension_dir = "ext" is located below "On windows:"),< a i=1>and change ext to the absolute path of the ext folder in the PHP environment

Then restart the Apache server,

Enter phpinfo(); in the .php file to check whether mysqli is successfully connected. If mysqli is displayed, it means the connection is successful.

  1. php:PHP 8.2 (8.2.13),, [8. New version, currently only this version is the latest, there is no problem configuring mysql, This new version of PHP 8.3 (8.3.0) has a configuration link exception]

<?php
$host='localhost';  // 数据库主机名
$username="root";   // 数据库用户名
$password="a6";  // 数据库密码
$dbname="mysql";    // 数据库名
$connID=mysqli_connect($host,$username,$password,$dbname);  // 建立数据库连接
if (mysqli_select_db($connID,$dbname)) {    // 选择数据库
    echo "数据库连接成功"; // 数据库连接成功
}
else  
{
    echo "数据库连接失败"; // 数据库连接失败
}
?>

appendix

<?php
 
phpinfo();
 
?>

Guess you like

Origin blog.csdn.net/zgscwxd/article/details/134900727