我似乎无法连接到数据库。下面是我的代码和我的数据库的屏幕截图,我正在尝试连接到remem539_test2
,但我一直收到“No DB”。所以我似乎可以连接,但它似乎无法找到数据库。有线索吗?
<?php
$db_host = "localhost";
$db_username = "remem539_test2";
$db_pass = "...";
$db_name = "remem539_test2";
@mysql_connect ("$db_host", "$db_username", "$db_pass") or die ("No Connection");
@mysql_select_db ("$db_name") or die ("No DB");
echo ("Succsess");
?>
答案 0 :(得分:1)
试试这个
$db_host = "localhost";
$db_username = "remem539_test2";
$db_pass = "...";
$db_name = "remem539_test2";
// Create connection
$conn = new mysqli($db_host, $db_username, $db_pass, $db_name);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";