Query to return multiple records in Store Procedure

Asked

Viewed 30 times

-1

I do not know if it is possible to perform this procedure to return several records.

I am developing an online game dissemination system in specific 'Mu Online'.

But I came across the following problem:

I’m 1 store procedure, and I need it to return to me all rows of records stored in the database related to a user.

I have a call from sp that brings me the invitation log for the online game, from her I guarantee the dados owner_id = (Owner of the online game) and server_id(online server id).

I already have the following code that brings to me .

$invitation_data =  $this->select('CALL
sp_call_select_server_invitations(:person_id, :owner_id, :server_id)',
$this->getParameters());

After I make a select of the records of the user owner of the online game, and also of the online server and would need that for each of these entities I return a record. However store procedure is returning me only the first record she finds. Because I am learning to manage now with stored procedures I decided to post my doubt here. If it is possible for my sp to return multiple records, how do I do this?

This is the code of procedure, everything is working properly without any error, but I would need you to return more than one record.

BEGIN
     SELECT `person_id` as owner_id , `server_id` as server FROM `server_invitations` WHERE ((`player_id` = person_id) and (`active` =
 1) and (`accept` = 0)); END
  • Thank you so much for editing, I’m new and I don’t know most of the rules. will serve me as an example, updating already solved the problem I created, was using the fetch function instead of fetchAll.

1 answer

0

Updating already solved the problem, was using the fetch function instead of fetchAll, just changed and the problem was solved.

public function select($query, $parameters) {

    $this->setDatabase('dvmufree');

    $conn = $this->getConnection();         $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $stmt = $conn->prepare($query);

    for ($i=0; $i < sizeof($parameters); $i++) {            $stmt->bindParam("{$parameters[$i][0][0]}", $parameters[$i][1][0]);         }

    $stmt->execute();       return $stmt->fetchAll(PDO::FETCH_ASSOC);

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.