views:

34

answers:

2

I have a table 'account' (id, email, pass) in MySQL database.

I have stored procedure:

DELIMITER $$
CREATE PROCEDURE `LoadAccount`(email_p VARCHAR(100))
BEGIN
    SELECT pass FROM account WHERE email = email_p;
END$$
DELIMITER ;

And here's the code:

function loadAccount($email, $pass)
{
  // connect to DB
  // ...
  $query = "CALL LoadAccount('{$email}')";

  if ($mysqli->multi_query($query))
  {
    do
    {
      if ($result = $mysqli->store_result())
      {
        // Numbered array.
        while ($row = $result->fetch_array(MYSQLI_NUM))
        {
          printf("%s %s\n", $row[0]);
        }

        // Associative array.
//        while ($row = $result->fetch_array(MYSQLI_ASSOC))
//        {
//          printf("%s\n", $row['pass']);
//        }
        $result->free();
      }
      $mysqli->more_results();
    } while ($mysqli->next_result());
  }
}

So, Numbered array section works, but if I comment it out and uncomment Associative array section — the page just hangs and loses connection.

Why doesn't it work?

+1  A: 

Not sure if the typo is in your code or not but:

printf("%s\n", $row[pass]);

should be:

printf("%s\n", $row['pass']);
anomareh
No, that's not it. It hangs even if I do nothing inside the loop. You're right about missing quotes though.
z-boss
A: 

Well, for weird things like that reinstalling of PHP helps! At least it did this time.

z-boss