Quantcast
Channel: Recent posts across whole site
Viewing all articles
Browse latest Browse all 49199

Problems using db_query in a custom service

$
0
0

It's quite weird, but maybe someone has already encountered the same problem.
The code, a service callback, is quite simple:

function myservice_service_search_products($query) {
  $sql = "SELECT * FROM mv_products WHERE description LIKE '%". mysql_real_escape_string($query) ."%'";
  $result = db_query($sql);

  $products= array();
  while ($product = db_fetch_object($result)) {
    $products[] = $product;
  }
  return $products;
}

When I call it first time with a parameter (let's say "red"), it returns correctly the set of data. On subsequent calls with different parameters ("black", "blue" or whatever) it returns an empty dataset. If I call again with the first parameter ("red") I receive back again the correct dataset.
I checked this on two different systems (one Mac and one Linux, with different PHP/Mysql combination) with same results. So the error is sure mine, but I can't find it...
It seems like a handle has not been released and any call to that table works on the first dataset only...
Or maybe it's not possible to use db_query within a web service?
Other hint: of course querying the database directly with the SQL produces always the correct dataset.

Any help is appreciated...


Viewing all articles
Browse latest Browse all 49199

Trending Articles