gpt4 book ai didi

php - 为什么我的 JSON 数组查询不起作用?

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

任何人都可以看到我的代码有什么问题/哪里出了问题吗?

我知道我有正确的主机、数据库、用户和密码。

这是 php 文件中的代码,它应该从我的 SQL 数据库中获取有关玩家的所有可用详细信息,但是如果我进入该页面,它只会给我一个白色页面。我使用 godaddy 作为主机,我的数据库也在那里。

有什么想法吗?谢谢

<?php

$host = "abc12345"; //Your database host server
$db = "abc12345"; //Your database name
$user = "abc12345"; //Your database user
$pass = "abc12345"; //Your password

$connection = mysql_connect($host, $user, $pass);

//Check to see if we can connect to the server
if (!$connection) {
die("Database server connection failed.");
} else {
//Attempt to select the database
$dbconnect = mysql_select_db($db, $connection);

//Check to see if we could select the database
if (!$dbconnect) {
die("Unable to connect to the specified database!");
} else {

$query = "SELECT * FROM Player";
$resultset = mysql_query($query);

$records = array();

//Loop through all our records and add them to our array
while ($r = mysql_fetch_assoc($resultset)) {
$records[] = $r;
}

//Output the data as JSON
echo json_encode($records);
}
}
?>

最佳答案

脚本没问题,我用不同的查询检查了它。

假设表 Player 不为空,则错误可能是您的原始 sql 查询(如注释中的 @Sharikov 指出的),否则错误与您配置的方式有关Godaddy 服务器。

为了进行调试,我建议在执行查询之前插入虚拟 print_recho 语句,并浏览您的 apache 日志: /var/log/apache2/access.log

还要确保您的服务器上没有缺少任何核心 php 软件包(例如 php5-mysql 如果您使用 mysql )。

关于php - 为什么我的 JSON 数组查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22590561/

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