我正在使用我的网站数据库与php mysql_connect,但我的托管服务提供商说我需要使用mysqli_connect。
当我编辑连接文件并更新更改方法时,它无法使用mysqli。
目前正在使用此代码:
MSQL方法:
$con=mysql_connect("localhost","username","password");
mysql_select_db("databasename");
对于mysqli我正在使用此代码但失败
MYSQLI方法:
$con = mysqli_connect("localhost","my_user","my_password","my_db");
请帮忙。为什么mysqli不工作?我的方法不对吗?
答案 0 :(得分:0)
试试这个:
示例(MySQLi面向对象)
<?php
$servername = "localhost";
$username = "username";
$password = "password";
` $dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
示例(MySQLi程序)
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>