Hi,

Stored proc code below works fine in MySQL command prompt. It returns John because it is in table. However, i can't return or read the Out parametter in PHP. I mean i cant retrieve John. I did ask this in PHP forum but no answer.

CREATE PROCEDURE `findname`(IN name_in varchar(15), OUT name_out varchar(15))
BEGIN
	SELECT name INTO name_out FROM table WHERE name=name_in;
END;

CALL findname('John', @out);
SELECT @out;
$query = "CALL findname('John', @err);";
$run = mysql_query("SELECT @err");

What do i write to check if result is returns John or not?

Thanks

Recommended Answers

All 3 Replies

Why cant you run a single query

SELECT name FROM table WHERE name=name_in;

Some thing like this....

$sql = "SELECT name FROM table WHERE nam='$name_out'";
$result = mysql_query($sql, $db);
$row = mysql_fetch_row($result);
$name_from_db=$row[0];

if($name_out = $$name_from_db)
{
echo "It's John";
exit;
}

I am not expert in Php though

Because, i want to learn how to read OUT parameter.

Just My taught

@out variable means you are creating a temporary variable
Temporary variables are connection specific

make sure these both are executed on one connection

$query = "CALL findname('John', @err);";
$run = mysql_query("SELECT @err");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.