0

我从我的云服务器请求这个 php

http://54.249.251.55/php/1_index.php

但结果是空的,我在本地尝试它给了我一个 json 结果。

localhost/php/1_index.php

这是我的 PHP

<?php

mysql_connect("54.249.251.55","MYID","MYPASS"); //connect database
mysql_select_db("aubook");//select name of the database
$cmd = "select * from book limit 0,20";
$sql=mysql_query($cmd);

while($row=mysql_fetch_assoc($sql))
    $output[]=$row;
print(json_encode($output));
mysql_close();

?>

我在 MYSQL 中的数据在服务器和本地都是一样的

你有什么建议吗??

在 localhost 我得到这个数据

[{"bid":"B001","name":"Software design structure for Ebook application","booktype":"research","authorid":"5555555","url":"n\/a","description":""},{"bid":"B002","name":"High-level code generation for ebook viewer ontology","booktype":"research","authorid":"5555554","url":"n\/a","description":""},{"bid":"B003","name":"Toward study of photo capturing for a class of plantation investigation","booktype":"research","authorid":"1234567","url":"n\/a","description":""},{"bid":"B004","name":"Unique solution to extract spiral DNA from monkey typeA","booktype":"research","authorid":"7654321","url":"n\/a","description":""}]

请帮忙

预先感谢

4

1 回答 1

0

只是暂时在调试时,您需要稍微扩展代码来解释它:

<?php

mysql_connect("54.249.251.55","MYID","MYPASS"); //connect database
echo mysql_error();
mysql_select_db("aubook");//select name of the database
echo mysql_error();

$cmd = "select * from book limit 0,20";
$sql=mysql_query($cmd);
echo mysql_error();

while($row=mysql_fetch_assoc($sql))
    $output[]=$row;

if (count($output) == 0)
    echo "The database contained no records.";

print(json_encode($output));
mysql_close();

?>
于 2013-06-17T11:23:10.963 回答