Any could give me a PHP script on how to call or execute mysql stored procedure.

Thank you.

Roland

Before you installed the php_mysqli.dll

<?php


/* Connect to a MySQL server */
$link = mysqli_connect(
'localhost',  /* The host to connect to */
'root',       /* The user to connect as */
'root',   /* The password to use */
'db_name');     /* The default database to query */


if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}



/* Send a query to the server */
if ($result = mysqli_query($link, "call se_proc('crm')")) {



/* Fetch the results of the query */
while( $row = mysqli_fetch_array($result) ){


echo ($row[0]. "--------- SR. " . $row[1] . "<br>");


}


/* Destroy the result set and free the memory used for it */
mysqli_free_result($result);
}


/* Close the connection */
mysqli_close($link);
?>

Edited 3 Years Ago by happygeek: fixed formatting

DROP PROCEDURE IF EXISTS `UsersR_DELETE_byPK` 
GO

CREATE PROCEDURE UsersR_DELETE_byPK
   (
        IN  UsersID             INT(11) 
)	
BEGIN 

   DELETE FROM UsersR   
                     
           WHERE  UsersID=UsersID;
                             
        
  END

it is my stored proceder how to call php code perfom delete operation

Edited 7 Years Ago by nav33n: Please use [code] tags to wrap your code.

Any could give me a PHP script on how to call or execute mysql stored procedure.

Thank you.

Roland

I'll give you a very simple connection.. and how to call a procedure very simply. here it is -
------->

//first create a connection to your database...
function connection(){
		$mysqli = new mysqli('$hostname','$dbusername', '$dbpassword', '$dbname');
		if (mysqli_connect_errno()) {
			printf("Connect failed: %s\n", mysqli_connect_error());
			exit();
		}
		
		return $mysqli;
		
	} 
//second create the function to call the stored procedure
  function query($query){
//call the connection function
  if($result = connection()->query($query)){
			while($row = $result->fetch_assoc()){
					$data[] = $row;
			}
			return $data;
			}else {
			print('error on:'.$query.mysqli_error($this));
                      }
 }
//then call the function to execute stored procedure
query("call store_proc('$param1')");

done! it's that simple... thanks

Edited 6 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

Problem when

$param1 = "Sky's Blue";
query("call store_proc('$param1')");

I'll give you a very simple connection.. and how to call a procedure very simply. here it is -
------->

//first create a connection to your database...
function connection(){
		$mysqli = new mysqli('$hostname','$dbusername', '$dbpassword', '$dbname');
		if (mysqli_connect_errno()) {
			printf("Connect failed: %s\n", mysqli_connect_error());
			exit();
		}
		
		return $mysqli;
		
	} 
//second create the function to call the stored procedure
  function query($query){
//call the connection function
  if($result = connection()->query($query)){
			while($row = $result->fetch_assoc()){
					$data[] = $row;
			}
			return $data;
			}else {
			print('error on:'.$query.mysqli_error($this));
                      }
 }
//then call the function to execute stored procedure
query("call store_proc('$param1')");

done! it's that simple... thanks

Hi !

Have a problem when parameter with single quote.

$param1 = "Test's Postt's";
query("call store_proc('$param1')");

Please help me to fix this.

Edited 3 Years Ago by Reverend Jim: Fixed formatting

This question has already been answered. Start a new discussion instead.