gpt4 book ai didi

php - 无法将 SQL 数据库表显示到 PHP 页面

转载 作者:搜寻专家 更新时间:2023-10-30 20:09:18 25 4
gpt4 key购买 nike

我正在尝试显示数据库中某个表的特定行。

Here is my code for it:
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else printf("Connection Successful");

mysql_select_db('magento');
$query = "SELECT * FROM poll_answer";
$result = mysqli_query($query);


while($poll=mysqli_fetch_assoc($result)){
echo "<tr>" .$poll['answer_title']. "</td>";
}

这是我的 table :

+--------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+----------------+
| answer_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| poll_id | int(10) unsigned | NO | MUL | 0 | |
| answer_title | varchar(255) | YES | | NULL | |
| votes_count | int(10) unsigned | NO | | 0 | |
| answer_order | smallint(6) | NO | | 0 | |
+--------------+------------------+------+-----+---------+----------------+

除了“连接成功”,我无法打印任何内容!

谁能告诉我可能是哪里出了问题?

将 SQL 编辑为 SQLI,仍然是同样的问题

最佳答案

你正在混合使用 mysqlmysqli

改变

$result = mysql_query($query);
while($poll=mysql_fetch_assoc($result)){

$result = mysqli_query($conn , $query);
while($poll=mysqli_fetch_assoc($result)){

Check Manual

关于php - 无法将 SQL 数据库表显示到 PHP 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28923418/

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