0

I have a stored procedure:

delimiter //

create procedure userlogin(in eml varchar(50))

begin

  select * from users 

  where email = eml;

end//

delimiter ;

And the php:

$db = new mysqli("localhost","root","","houseDB");

$eml = "[email protected]";

$sql = $db->query("CALL userlogin('$eml')");

$result = $sql->fetch_array();

The error that I get from the browser when I run the php script:

Fatal error: Call to a member function fetch_array() on a non-object...

I am using phpmyadmin version 3.2.4 and mysql client version 5.1.41.

2 Answers 2

2

You have to use mysqli_multi_query, not query. Check http://us.php.net/manual/en/mysqli.multi-query.php , they have a good example

Sign up to request clarification or add additional context in comments.

2 Comments

Why does calling a stored procedure need mysqli_multi_query? He isn't creating it, he's just calling it, isn't he?
But it returns values. If it didn't, it would work as it is (actually, it's working, but in order to access result set from procedure we need to use multi_query).
0

mysqli::query returns false if the query fails (instead of returning a result object or true). You need to test whether the result actually is an object:

$sql = $db->query("CALL userlogin('$eml')");

if (is_object($sql)) 
$result = $sql->fetch_array();
else
printf("Error: %s\n", $sql->error);

You will probably get an error message explaining why calling the stored procedure didn*t work out.

2 Comments

$sql->error will also fail because false has no 'error' attribute. In case of false you can echo mysql_error(); to debug the error
@maid450 this is mysqli, not mysql.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.