Jump to content

mysql stored procedure selects 1, php array doesn't see the 1.


ThisisForReal

Recommended Posts

My friend and I are working on a website.  He is doing all the database operations, and I'm coding the PHP.  Neither of us are very well versed in this exciting world of coding and database design, but we're learning fast.

 

He created a stored procedure for updating a table.  When a user updates the form on our website, the stored procedure is called and the table is successfully updated in mysql.  To verify (and thus redirect the user to the appropriate page), the stored procedure ends by selecting 1 if successful, else 0.  We have tested this by running the stored procedure in mysql workbench (see attachment below).

 

On my end, I'm having trouble using the 'select 1' that he is sending me.  I've run gettype and echoed the variable, and it tells me that I'm working with an array, but it won't tell me whether it's a 1 (successfully updating table).  It simply says you have an array, and when I do my if{ and ask whether the value of the array is a 1 (or if I merely ask to echo the value), I can't work with the result.

 

We're trying to return a 1,0 result while keeping the load on our database to a minimum.  We could modify the stored procedure to perform logic on its end and return a 1 or a 0 from a table, but that sounds like a foolish way of solving the problem.  Does anyone know the sql terminology he needs to use to send me an array that I can work with.  Or am I making the error? (For reference, my php code is below).

 

$query = "CALL mealshare.spUpdateGroup('$mtgid','$description','','','','','$target')";
		$data = mysqli_query($dbc,$query) or die('Could not execute the command');
		$answer = mysqli_fetch_array($data);

		echo '<p> first is gettype answer<br />'; //my attempt at debugging (see picture attachment)
		echo gettype($answer);
		echo "$answer";
		echo $answer;


		if ($answer == 0) {...

 

Hope all that was clear as mud.

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.