How to create Mysql Stored Procedure

Step-1
---------

Create Procedure First

Example
----------

USE DATASERVICE_SAMPLE ;
DROP PROCEDURE If EXISTS getEmployee ;
CREATE PROCEDURE getEmployee(empNo INTEGER) SELECT employeeNumber,lastName,firstName,email FROM Employees where employeeNumber = empNo ;
USE DATASERVICE_SAMPLE ;
DROP PROCEDURE If EXISTS getEmployee2 ;
CREATE PROCEDURE getEmployee2(empNo INTEGER) SELECT employeeNumber,lastName,firstName,email FROM Employees where employeeNumber = empNo ;

Step 1 : save above as the file in some path: $path(test.sql)

Step 2 : go to command prompt mysql -u root -p

Step 3 : run -> source $path (ex: source test.sql)



IN PHP FILE:


$link = mysqli_connect('localhost','root', '', 'DATASERVICE_SAMPLE');

$result = mysqli_query($link,"CALL getEmployee('1002')");
if( $result ){
while( $row = mysqli_fetch_array($result) ){
print_r($row );
}
}






No comments: