我有一份声明以下查询:服务器count_client_locations
上为什么我不能通过PHP在准备好的查询中调用MySQL存储的函数?
SELECT
cid, cname, cemail, count_client_locations(cid) AS loc_cnt
FROM
clients
WHERE isactive = 1 ORDER BY cname ASC
我有一个存储功能。函数的查询部分看起来是这样的:
RETURN (SELECT COUNT(lid) FROM locations WHERE linked_client = cid);
当我运行在MySQL Workbench中的SQL,它返回所期望的结果:
cid | cname | cemail | loc_cnt
------------------------------------------------
2 | Acme Inc | [email protected] | 3
1 | Example Ind | [email protected] | 5
3 | Foobar Inc | [email protected] | 0
1 | Barfoo Ltd | [email protected] | 1
当我运行通过PHP的mysqli准备好的声明中,它未能准备(Fatal error: Call to a member function execute() on a non-object
)。如果我把这个函数的调用取出来,它可以正常工作。
编辑PHP代码:
$sql = $conn->prepare("SELECT cid, cname, cemail, count_client_locations(cid) AS loc_cnt FROM clients WHERE isactive = 1 ORDER BY cname ASC");
$sql->execute();
那么,为什么在MySQL工作台此查询工作,而不是在PHP代码,有什么我可以做些什么来解决呢?
@Drew - 我不确定我是否遵循你的意思。我得到了什么错误?查询? – dan
http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12769983#12769983' – Drew
没有什么真正革命性的吧 – Drew