Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
DB Class with mysql - select from stored procedure
  • Hello, I'm wondering if it is possible to use DB class with mysql to execute stored procedure which is supposed to return rows of data $result = \DB:query('CALL get_activities();')->execute(); where get_activities() is a mysql procedure which is: select * from activities; I tried the example above, it returned an integer value. I need to retrieve the data. Thanks and regards
  • any ideas?
  • I think for unknown reasons the current DB drivers only free the result if the result was significant. They were ported from the Kohana framework, so I don't know why. Please create an issue for this on http://github.com/fuel/core/issues to have it looked at.
  • Hello, not sure about this, but you can try:
    $result = \DB::query('CALL get_activities()', \DB::SELECT)
    ->execute(); in this way you tell DB class that it is a select, try playing with it :)
  • Jaroslav Petrusevic wrote on Monday 22nd of August 2011:
    Hello, not sure about this, but you can try:
    $result = \DB::query('CALL get_activities()', \DB::SELECT)
    ->execute(); in this way you tell DB class that it is a select, try playing with it :)

    Thanks huglester, it worked :)
  • i would like to add to this topic. i need to pass parameters to the mysql stored procedures. i have tried concatinating the parameter value in the 'call procedure()' string but it looks like it does not work. i did not get any error though. thanks
  • disregard my question.
    i was able to pass parameter by both contatinating the input parameter and by using the db query parameter binding feature.
  • Hi again, I had a different problem with calling procedures in fuelphp using DB class. When I call a procedure after calling another one, I get the following error: Fuel\Core\Database_Exception [ 2014 ]: Commands out of sync; you can't run this command now
    The code:
    $result = \DB::query('CALL get_activities()', \DB::SELECT)
       ->execute();
    
    $result = \DB::query('CALL get_another()', \DB::SELECT)
       ->execute();
    

    I investigated the issue, Mysql reference says that:
    This can happen, for example, if you are using mysql_use_result() and try to execute a new query before you have called mysql_free_result(). It can also happen if you try to execute two queries that return data without calling mysql_use_result() or mysql_store_result() in between.
    I wonder if this is a bug in fuelphp or is there something I am missing? Thanks and regards

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion