1

Is it possible to access an OUT variable from an SP called through mysqli without returning it via SELECT one way or another? I had a good look and tried the code here but it always needs a result set called within or after the SP to work.

Consider this code:

SQL:

DELIMITER $

# DROP PROCEDURE IF EXISTS outVar$

CREATE PROCEDURE outVar(OUT myVar TINYINT(1))
BEGIN

    SET myVar = 1;

END$

DELIMITER ;

CALL outVar(@myVar);

SELECT @myVar;

PHP:

 <?php

    $Conn = new mysqli("127.0.0.1", "root", "123456789", "test");

    $RResult = $Conn->query("CALL outVar(@myVar);");

    print_r($RResult->fetch_assoc());
?>

This returns the following:

Fatal error: Call to a member function fetch_assoc() on boolean in C:\xampp\htdocs\phpTest.php on line 7

Because there are no results returned in tabular form, fair enough. So am I correct in assuming that while OUT is elegant within mysql it's of no use in the mysqli context without the help of a result set leaving OUT redundant in this context? If not I'd love to know how to do it.

Thanks,

James

5
  • did you try SP page in mysqli manual? Commented Feb 10, 2017 at 11:55
  • I have now. P() in all cases either has no result, creates a result set using SELECT or the OUT is recovered using a subsequent SELECT and session variable. Is there an example where the procedure has an OUT, but no SELECT to create a result set and this value is available in PHP as it would be within MySQL? Commented Feb 10, 2017 at 12:12
  • I have an impression that the manual page is rather clear stating that mysqli does not have any support for out/inout variables whatsoever Commented Feb 10, 2017 at 12:18
  • To add insult to injury, even PDO_Mysql doesn't, though for other drivers it's supported Commented Feb 10, 2017 at 12:19
  • "The values of INOUT/OUT parameters are accessed using session variables." Well spotted, apologies for taking the long way round and thanks for the pointers. Good to know what's right. Commented Feb 10, 2017 at 12:24

0

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.