gpt4 book ai didi

php 连接并显示 mysql 表 - LAMP 服务器

转载 作者:行者123 更新时间:2023-11-29 20:55:13 25 4
gpt4 key购买 nike

我正在运行 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_query

$result = mysqli_query($conn,$sql);

关于php 连接并显示 mysql 表 - LAMP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37700238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com