我将JSONObject作为输入传递给php脚本,因为select查询需要执行并从数据库中获取值。但是,即使值存在于数据库中,这些值也不会从数据库中获取。
<?php
$username = "xxx";
$password = "xxxx";
$host = "localhost";
$database="xxxxx";
$server = mysql_connect($host, $username, $password);
$connection = mysql_select_db($database, $server);
//$jsonString = file_get_contents('php://input');
$jsonString ='{"ilist":{"ib1":"6","ib2":"5"},"rlist":{},"generelist":{"genere1":"Adventure","genere2":"Animation","genere3":"Comedy","genere4":"Horror","genere5":"Fantasy","genere6":"Mystery"},"yearlist":{}}';
$obj = json_decode($jsonString,true);
$ib=array();
$rn=array();
$genere=array();
$year=array();
foreach ($obj['ilist'] as $key => $value)
{
//echo "<br>------" . $key . " => " . $value;
$ib[$key] = $value;
}
foreach ($obj['rlist'] as $key => $value)
{
//echo "<br>------" . $key . " => " . $value;
$rn[$key] = $value;
}
foreach ($obj['yearlist'] as $key => $value)
{
//echo "<br>------" . $key . " => " . $value;
$year[$key] = $value;
}
$val1=implode(',', $ib);
$val2=implode(',', $rn);
$val4=implode(',', $year);
array_walk($obj['generelist'],function(&$item1, $key){$item1="$item1=1";});
$stringgen = implode(' OR ', $obj['generelist']);
$myquery = "SELECT * FROM Movies WHERE 'it' IN ('$val1') OR `Re` IN ('$val2') OR '". mysql_real_escape_string($stringgen) ."' OR `Year` IN ('$val4')";
$query = mysql_query($myquery);
if ( ! $query ) {
echo mysql_error();
die;
}
for ($x = 0; $x < mysql_num_rows($query); $x++) {
$data[] = mysql_fetch_assoc($query);
}
echo json_encode($data);
mysql_close($server); ?>
但它返回null值,即使数据库中存在的值也是如此。即使我从phpmyadmin在IE中打开php文件,它也会抛出null值。脚本出了什么问题。