Jump to content

mysqli_fetch_array() expects parameter on MySQL Output.


FraggleRock

Recommended Posts

Good day everyone.

 

I have a MySQL proc that I am using to create users in the database.  This proc returns a @userid which I am trying to set to a PHP variables.  The code below actually shows me trying to display it, which I would be happy with right now.

 

The code runs just find and there is no database error returned.  I have verified that the user actually gets created in the database.  As such, I am leaning towards something being wrong with the PHP code, or more than like, my understanding of what I should be doing inside the PHPcode. 

 

While I realize there are PHP functions that would get the last created userid in the system, I need to be able to store output variables for other procedures as well. 

 

Any and all help is greatly appreciated. 

 

FraggleRock

 

Database code that has been verified working is as follows:

CALL CreateUser('Nathan', 'Houston', '[email protected]', 'reallylongstring', @o_UserID);
SELECT @o_UserID AS userid;

 

PHP Code that I am using to try and accomplish the same thing:

		require_once('mysqli_connect.php');

	$query = "CALL CreateUser ('$fn', '$ln','$email',SHA1('$pw'), @userid);";
	$query = $query . 'Select @userid as userid';

	$result = mysqli_multi_query($dbc, $query) or die("MySQL error: " . mysqli_error($dbc) . "<hr>\nQuery: $query");;

	if($result)
	{
		echo '<h1>Thank You!</h1><p>You are now registestered.  WELCOME!</p><p><br></p>';

	//	echo 'the value of $result is: ' . $result;

		while($row  = mysqli_fetch_array($result, MYSQL_NUM))
		{
			echo 'Potential output parameter is: ' . $row[0];

		}
	}
	else
	{
		echo('<h1>System Error</h1><p class="error">You could not be registered at this time.  We aplogize for the issue and ask that you return in 24 hours</p>');

		echo('<p>'.mysqli_error($dbc).'<br /><br />Query'.$query.'</p>');
	} // end if($results)

	mysqli_close($dbc);

 

 

According to http://php.net/manual/en/mysqli.multi-query.php, mysqli_multi_query returns a bool, and you need to use:

http://www.php.net/manual/en/mysqli.use-result.php

 

So you would replace $result=mysqli_multi_query....

with

mysqli_multi_query($dbc, $query) or die("MySQL error: " . mysqli_error($dbc) . "<hr>\nQuery: $query");
$result=mysqli_use_result();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.