I have the following query in a prepared statement:
SELECT 
  cid, cname, cemail, count_client_locations(cid) AS loc_cnt
FROM 
  clients 
WHERE isactive = 1 ORDER BY cname ASC
I have a stored function on the server count_client_locations. The query part of the function looks like this:
RETURN (SELECT COUNT(lid) FROM locations WHERE linked_client = cid);
When I run the SQL in MySQL Workbench, it returns the desired result:
cid | cname       | cemail            | loc_cnt
------------------------------------------------
2   | Acme Inc    | fred@example.com  | 3
1   | Example Ind | alice@example.com | 5
3   | Foobar Inc  | joe@example.com   | 0
1   | Barfoo Ltd  | hello@example.com | 1
When I run that via PHP mysqli prepared statement, it fails to prepare it (Fatal error: Call to a member function execute() on a non-object). If i take out the call to the function, it works fine.
EDIT PHP code:
$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();
So why does this query work in MySQL workbench, and not in the PHP code, and is there anything I can do to fix it?
 
    