我只是尝试用PHP打印我的MySQL数据库的内容。
我的数据库是这样的:
mysql> show tables;
+-------------------+
| Tables_in_myTable |
+-------------------+
| users |
+-------------------+
1 row in set (0,00 sec)
mysql> select * from users;
+------------+
| name |
+------------+
| Nick |
+------------+
1 row in set (0,00 sec)我的PHP代码如下所示:
<?php
echo "HI"; //to see, that the php gets runned at all.
$connection = mysql_connect('localhost', 'root', ''); //The Blank string is the password
mysql_select_db('myTable');
$query = "SELECT * FROM users";
$result = mysql_query($query);
echo "<table>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>" . $row['name'] . "</td></tr>";
}
echo "</table>";
mysql_close();
?>但在网站上,我得到的唯一输出是
"HI"我在PHP中检查了用户名、passwd和DB-名称。
我正在Ubuntu (Ubuntu,如果这重要的话)上运行一个apache2服务器,16.10和MySQL的社区版本
发布于 2017-02-13 17:26:25
发布于 2017-02-13 17:28:11
考虑到您的错误消息Call to undefined function mysql_connect(),它可能看起来像一个缺少mysql_库的版本。
mysql_库在7.x,这有很多原因中被删除。要么使用mysqli或PDO重写代码,要么将PHP版本降级为5.x (尽管我强烈建议不要这样做)。
https://stackoverflow.com/questions/42209815
复制相似问题