0

下面返回“\nQuery was empty”,因为我只是从我的服务器使用浏览器中的 URL 运行它。

这是PHP代码:

    <?

$databasehost = "server";
$databasename = "xxxx";
$databaseusername ="xxxx";
$databasepassword = "xxxx";
$query = "SELECT * FROM  `Tailor`LIMIT 0 , 30";
$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
$query = file_get_contents("php://input"); 
$sth = mysql_query($query);

if (mysql_errno()) { 
    header("HTTP/1.1 500 Internal Server Error");
    echo $query.'\n';
    echo mysql_error(); 
}
else
{
    $rows = array();
    while($r = mysql_fetch_assoc($sth)) {
        $rows[] = $r;
    }
    print json_encode($rows);
}
?>
4

3 回答 3

1

无需使用 file_get_content 并且您必须在表名后放置一个空格。

<?php

$databasehost = "server";
$databasename = "xxxx";
$databaseusername ="xxxx";
$databasepassword = "xxxx";
$query = "SELECT * FROM  `Tailor` LIMIT 0 , 30";
$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
 mysql_select_db($databasename) or die(mysql_error());

$sth = mysql_query($query);

if (mysql_errno()) { 
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysql_error(); 
}
else
{
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
    $rows[] = $r;
}
print json_encode($rows);
}
?>
于 2013-05-02T05:56:36.970 回答
0

您的查询有问题,您需要在表名后使用空格

SELECT * FROM  `Tailor` LIMIT 0 , 30
于 2013-05-02T05:51:38.320 回答
0

第一的

$query = "SELECT * FROM  `Tailor`LIMIT 0 , 30";

但你覆盖它

$query = file_get_contents("php://input"); 

// $query like   aaa=ggg&bbb=kkk

那么你

$sth = mysql_query($query);

// LIKE $sth = mysql_query('aaa=bbb&ccc=lll'); //it not sql query format
于 2013-05-02T06:01:48.893 回答