進出口運行一個LAMP服務器和IM試圖在網頁上顯示我的數據庫的表PHP連接並顯示MySQL表 - LAMP服務器
這是我的PHP腳本
$servername = "127.0.0.1";
$username = "root";
$password = "none";
$dbname = "chegada";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}else{echo "OK!";}
$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);
if (!$result) {
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
以及網頁顯示這
Warning: mysqli_connect(): (HY000/2002): Connection refused in /var/www/html/index.php on line 16
Notice: Trying to get property of non-object in /var/www/html/index.php on line 17
OK!
Fatal error: Uncaught Error: Call to undefined function mysql_query() in /var/www/html/index.php:22 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 22
有人可以幫我這個嗎?
將mysqli與mysql混合使用 – Saty
不要使用不推薦使用的'mysql_ *'函數,而是使用MySQLi/PDO。 – Raptor
$ password =「」; – JYoThI