Home > Article > Backend Development > Two ways to connect MySQL with PHP and prevent garbled characters_PHP tutorial
MySQL configuration for PHP
Error message: Class 'mysqli' not found in
Answer:
1. In conf/php.ini, use "/php_mysql" in vim to search for extension=php_mysql.dll, and remove the previous ";",
Also add extension=php_mysqli.dll;
Note that the dll at the back has an extra i
2. "/extension_dir" check whether the path is correct;
3. Find the ext/ directory and copy the two files php_mysql.dll and php_mysqli.dll to %systemroot%/system32.
4. Restart the service
Connect to database
//In conf/php.ini, use "/php_mysql" in vim to search extension=php_mysql.dll, remove the ";" in front, and add extension=php_mysqli.dll;
$mysqli = new mysqli("127.0.0.1","Username", Password","Library Name");
$query="select * from table order by theindex desc";
$mysqli->query("SET NAMES gb2312");//Note that if you don’t add it here, the code will be garbled
$result = $mysqli->query($query);
//printf() function outputs a formatted string
while(list($name, $theindex) = $result->fetch_row())
echo("
".$name.$theindex);
$con = mysql_connect("localhost", "username", "password");
if ($con) {
mysql_query("set names 'gb2312'");
mysql_select_db("Library Name", $con);//Note that if you don’t add it here, it will cause garbled characters
$rs = mysql_query("select * from table order by theindex desc;", $con);
If ($rs) {
echo ("
$row[theindex] | " .$row[name] | " .
www.bkjia.com