[英]phpMyAdmin sql query is always returning 500 Internal Error?
I'm new to PHP.I have been trying to get data from Database and convert them to json .我是 PHP 新手。我一直在尝试从数据库中获取数据并将它们转换为 json 。 However when I open the chrome console.
但是,当我打开 chrome 控制台时。 It says 500 : Internal Server Error.
它说 500:内部服务器错误。 Here is my PHP Code
这是我的 PHP 代码
<?php
function get_data(){
$link = mysqli_connect("localhost:8889","root2","root","EMPLOYEE");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
$sql = "SELECT * FROM people";
$result = mysqli_query($link,$sql);
$json_array = array();
while($row = mysql_fetch_array($result))
{
$json_array[] = array(
'id' => $row["id"],
'name' => $row["name"]
);
}
$json_array['name'] = "sarath";
$json_array['age'] = 19;
#echo $json_array;
return json_encode($json_array);
}
echo '<pre>';
print_r(get_data());
echo '</pre>';
?>
I get the following output at http://localhost:8888/peo.php .我在http://localhost:8888/peo.php得到以下输出。 The json_array was not getting printed.
json_array 没有被打印出来。
<pre>Success: A proper connection to MySQL was made! The my_db database is great.
Host information: localhost:8889 via TCP/IP
THE DATABASE IMAGE FROM PHPMyAdmin has been linked here来自 PHPMyAdmin 的数据库图像已在此处链接
1) You open the connection using mysqli_connect
but later use mysql_fetch_array
. 1)您使用
mysqli_connect
打开连接,但稍后使用mysql_fetch_array
。 Change it to mysqli_fetch_array
: those are different drivers.将其更改为
mysqli_fetch_array
:这些是不同的驱动程序。
2) Are you sure that you have got json
addon installed? 2) 你确定你已经安装了
json
插件吗? You can check it using phpinfo();
您可以使用
phpinfo();
来检查它phpinfo();
or just try to var dump: var_dump(json_encode(['something']));
或者只是尝试 var dump:
var_dump(json_encode(['something']));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.