mneva
mneva

Reputation: 33

mysql stored procedures using php

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.

Upvotes: 0

Views: 764

Answers (2)

a1ex07
a1ex07

Reputation: 37364

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

Upvotes: 2

Pekka
Pekka

Reputation: 449435

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.

Upvotes: 0

Related Questions