Jump to content

Call MysQL stored procedure using PHP5.0


CanMike

Recommended Posts

Help,

 

I've upgraded to MySQL 5 & PHP 5 so that I can use stored procedures.

 

I've successfully and tested (from the mysql command line) a compile a stored procedure add_stuff.sql

 

delimiter ~

create procedure add_stuff( IN inC1 text)
                            
BEGIN

  INSERT INTO t1 (c1) VALUES (inC1);
   
END ~

delimiter ;

 

So I wrote some PHP to test the call:

 

<?php # add_stuff.php

$conn = @mysqli_connect('localhost', 'miketest', 'mike', 'test1');

if (mysqli_connect_errno()) 
{
   printf("Connect failed: %s\n", mysqli_connect_error());
   exit();
}

$c1 = 'mike';

  
$result = @mysqli_query ($conn, 'call add_stuff($c1)');

  
if (mysqli_affected_rows($conn) == 1)
{
  printf("Success");
}
else
{
printf("Errormessage Details: %s\n", mysqli_error($conn));
}
  
mysqli_close($conn);
?>

 

As you can see, I have not enclosed the variable $c1 in either single or double quotes in this version.

When I run this code I get this error: Errormessage Details: Unknown column '$c1' in 'field list'

 

So then I changed the call to 'call add_stuff('.$c1.') and I get the error: Errormessage Details: Unknown column 'mike' in 'field list'

 

I've been working with Oracle stored procedures for years, so I quite comfortable with the structure, but I'm lost when it comes to CALLING the SP from PHP.

 

What am I doing wrong?  How do I pass an argument within a call statement?

 

Thanks

 

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.