Php 可捕获的致命错误:由于mysql查询,类stdClass的对象无法在中转换为字符串
在android编程中,我使用jsonarray时,当我键入简单查询时,它可以工作,但当我在php函数中键入查询时,它返回错误: Php代码:Php 可捕获的致命错误:由于mysql查询,类stdClass的对象无法在中转换为字符串,php,android,mysql,Php,Android,Mysql,在android编程中,我使用jsonarray时,当我键入简单查询时,它可以工作,但当我在php函数中键入查询时,它返回错误: Php代码: session_start(); $friendlocs=$db->getFriendsLocations($_SESSION['email']); $a=array(); $b=array(); if ($res){ while ($row = mysql_fetch_array($friendlocs)) {
session_start();
$friendlocs=$db->getFriendsLocations($_SESSION['email']);
$a=array();
$b=array();
if ($res){
while ($row = mysql_fetch_array($friendlocs))
{
//$b["id"] = $data[$j]->id;
$b["f_name"] = $row[0];
$b["f_email"] = $row[0];
$b["f_lat"] = $row[1];
$b["f_lon"] = $row[2];
$b["f_time"] = $row[3];
$b["f_timezone"] = $row[4];
$b["f_synctime"] = $row[5];
$b["f_friend_status"] = $row[6];
array_push($a,$b);
}
}
echo json_encode($a);
Php函数和查询:
public function getFriendsLocations($user_email) {
// THIS QUERY RETURNS ERROR BUT IF I RUN THIS QUERY IN MYSQL EDITOR, IT WORKS
$result = mysql_query("select user_email,and_loc_lat, and_loc_long, and_loc_time, and_loc_timezone, and_sync_time, user_loc_status FROM tbl_currentlocs WHERE user_email = ANY (select DISTINCT friend_email FROM tbl_friendship WHERE user_email = '$user_email')");
//IF I USE result2 query it works on php and JSON
$result2 = mysql_query("select user_email,and_loc_lat, and_loc_long, and_loc_time, and_loc_timezone, and_sync_time, user_loc_status FROM tbl_currentlocs"); // WHERE user_email = '$user_email'
return $result;
谢谢你的帮助。当我更改php函数代码时,它工作正常。我认为某些sql语法无法工作。当我键入上面的查询和新查询时,它们都从mysql SQL编辑器返回相同的值,但是当我使用上面的SQL查询和IN以及任何单词时,它在php函数到json代码中不起作用 以下是我的新查询:
public function getFriendsLocations($user_email) {
$result = mysql_query("select t1.user_email,t1.and_loc_lat, t1.and_loc_long, t1.and_loc_time, t1.and_loc_timezone, t1.and_sync_time, t1.user_loc_status FROM tbl_currentlocs t1 INNER JOIN tbl_friendship t2 ON t1.user_email=t2.friend_email AND t2.user_email='$user_email'");
return $result;
}
在while循环中,尝试var_dump($row)并在此处发布您的输出,当我更改php函数代码时,它可以工作: