how to handle two or more query results from a storedprocedure

Discussion in 'PHP' started by clobberx, Jun 11, 2008.

  1. #1
    What if the mysql stored procedure returns two or more query results and how to handle those results sets in php
     
    clobberx, Jun 11, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Generally you need to use the mysqli query and use the mysqli_multi_query function.

    Haven't tested but this should get you on the right track.

    
    
    $db = new mysqli(.....);
    
    $my_sp_query = "call my_sp()";
    
    if($query = $db->multi_query($my_sp_query))
    {
    $result_array = array();
    while($query->next_result())
    {
    if($result = $query->store_result()
    {
    //you can use the $result_array for later, or you can execute / print stuff here
    $result_array[] = $result->fetch_array();
    
    $result->free_result();
    }
    }
    }
    
    
    PHP:
     
    jestep, Jun 11, 2008 IP
  3. clobberx

    clobberx Active Member

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #3
    sounds good

    is mysqli extension default loaded for php in every webhosting apache server
     
    clobberx, Jun 11, 2008 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    It is fairly standard with most php5 installs. You can use a phpinfo to tell if the mysqli functions are enabled.
     
    jestep, Jun 12, 2008 IP
  5. clobberx

    clobberx Active Member

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #5
    ok fine thanks
     
    clobberx, Jun 13, 2008 IP