我有一份聲明以下查詢:服務器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