gpt4 book ai didi

php - 相同的连接查询: two different results through Phalcon and phpMyAdmin

转载 作者:行者123 更新时间:2023-11-30 00:05:26 25 4
gpt4 key购买 nike

我正在使用 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é”,但为空。示例输出:

[{"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 个表 users、favorites、commons 和province,并且只有这些字段用于查询。其他任何东西都没有用。

这对我来说完全没有意义......请帮忙!

Apache 版本 2.4.4

PHP 版本 5.4.12

MySql版本5.6.12

Phalcon 版本 1.3.2

Windows 7 64位操作系统

最佳答案

这是因为通用名末尾有一个特殊字符“é”。显然,如果 json_encode 包含此类字符,则会跳过该字段。我通过直接在公共(public)表中转义特殊字符来解决。

关于php - 相同的连接查询: two different results through Phalcon and phpMyAdmin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24600081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com