I have used mysql stored procedure in php, but i need to return few values from my sql, so i am planning to use mysql functions or stored procedure with ''out'parameter.
it would be good if anyone can help me on that.
I have used mysql stored procedure in php, but i need to return few values from my sql, so i am planning to use mysql functions or stored procedure with ''out'parameter.
it would be good if anyone can help me on that.
i found solution for this
http://blog.ulf-wendel.de/2011/using-mysql-stored-procedures-with-php-mysqli/
$mysqli = new mysqli("localhost", "root", "", "test");
if (!$mysqli->query("DROP PROCEDURE IF EXISTS p") ||
!$mysqli->query('CREATE PROCEDURE p(OUT msg VARCHAR(50)) BEGIN SELECT "Hi!" INTO msg; END;'))
echo "Stored procedure creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
if (!$mysqli->query("SET @msg = ''") ||
!$mysqli->query("CALL p(@msg)"))
echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
if (!($res = $mysqli->query("SELECT @msg as _p_out")))
echo "Fetch failed: (" . $mysqli->errno . ") " . $mysqli->error;
$row = $res->fetch_assoc();
echo $row['_p_out'];