Friday, 3 July 2015

How to CREATE and EXECUTE Store Procedure in PHP.

Definition:  

        What is Store Procedure: Store Procedure is the database object.
Store procedure is pre-compiled code. By using store procedure we are able to call the functions. Store procedure is the

HOW TO CREATE STORE PROCEDURE:

Write and execute below code in mysql.

DELIMITER  $$
CREATE PROCEDURE procedurename()
BEGIN

          SELECT columnname1, columnname2 FROM  Database.table ;

END $$

DELIMITER  ;


HOW TO CALL THE STORE PROCEDURE TO PHP using PDO:

include 'pdodatabase.php';
$sql="CALL procedurename";
try{
      $stmt=$databaseobject->prepare($sql);
      $stmt->execute();
      $result=$stmt->fetchAll();
}
catch(exception $e){
     exit;
}
foreach($result as $rs){
    echo $r["columnname1"];
}

No comments:

Post a Comment