我正在使用php Phalcon框架。
使用phalcon执行查询:
$rawQuery =
'SELECT users.ID, users.Name, users.ProfilePictureUrl, users.Birthday, GetAge(users.Birthday) as Age, ' .
' users.Sex, users.LookingFor, commons.Name as CommonName, provinces.Name as ProvinceName, users.LastOnline FROM favorites ' .
'INNER JOIN users ON favorites.FavoriteUserID = users.ID ' .
'INNER JOIN commons ON commons.ID = users.CommonID ' .
'INNER JOIN provinces ON provinces.ID = commons.ProvinceID ' .
'WHERE favorites.OriginUserID = ' . $this->ID;
return $this->getReadConnection()->query($rawQuery)->fetchAll();
此查询正确返回所有字段,但CommonName除外,它应为字符串'Aglié',但为null。样本输出:
[{"ID":"2","0":"2","Name":"Olga","1":"Olga","ProfilePictureUrl":"asd","2":"asd","Birthday":"2014-07-09","3":"2014-07-09","Sex":"f","4":"f","LookingFor":"girls","5":"girls","CommonName":null,"6":null,"ProvinceName":"Torino","7":"Torino","LastOnline":null,"8":null}]
另一方面,通过phpMyAdmin执行相同的查询:
SELECT users.ID, users.Name, users.ProfilePictureUrl, users.Birthday, GetAge(users.Birthday) as Age,
users.Sex, users.LookingFor, commons.Name as CommonName, provinces.Name as ProvinceName, users.LastOnline FROM favorites
INNER JOIN users ON favorites.FavoriteUserID = users.ID
INNER JOIN commons ON commons.ID = users.CommonID
INNER JOIN provinces ON provinces.ID = commons.ProvinceID
WHERE favorites.OriginUserID = 1
它无限期地挂起。但是,如果我取出Age字段,它将返回所有正确的字段,包括CommonName(有效字符串)。样本输出:
ID, Name, ProfilePictureUrl, Birthday, Sex, LookingFor, CommonName, ProvinceName, LastOnline
2, Olga, asd, 2014-07-09, f, girls, Agliè, Torino, NULL
GetAge(生日)定义如下:
return DATE_FORMAT(FROM_DAYS(DATEDIFF(curdate(),birthday)), '%Y')
您可以简单地假设只有4个表用户,收藏夹,公共区和省,只有查询中使用的那些字段。其他任何东西都没用。
这对我来说完全没有意义......请帮助!
Apache版本2.4.4
PHP版本5.4.12
MySql版本5.6.12
Phalcon版本1.3.2
Windows 7 64位操作系统
答案 0 :(得分:0)
这是因为普通名字末尾的特殊字符'é'。显然json_encode会跳过该字段,如果它包含这样的字符。我通过直接在公共表中转义特殊字符来解决。