call store procedure using php

Connection.class.php

/*
* Connection Class(Connection.class.php)
*/
<?php

class Class_Connection extends mysqli{
public function
__construct($host, $user, $pass, $db) {
       
parent::__construct($host, $user, $pass, $db);

        if (

mysqli_connect_error()) {
           
drupal_set_message("Could not connect to the database. MySQL error: ".mysqli_connect_error(), 'warning');
        }
       
      
    }
     }
?>

Data.php

/*
* Storeprocedure fuction class(Data.php)
*/

<?php
require_once('Class/Connection.class.php');

class DAO_data{
    
   
/*
     * Calling Select Data StoreProcedure.
     */
  
   
function SP_getData(){
     
       
$mysqli = new Class_Connection('<dbHost>','<username>','<password>','<database>');
       
$query = "CALL getUserdata()";
           
        if (
$mysqli->multi_query($query)) {
          
            if (
$result = $mysqli->store_result()) {
               
$MyArray = array();
                while (
$row = $result->fetch_object()) {
                   
$MyArray[] = $row;
                }
               
$result->free();
              
$mysqli->next_result();
            }
          
        }
        return
$MyArray;
      
    }
  
   
/*
     *  Insert Data StoreProcedure.
     */
  
   
function SP_insertData($id,$name,$email,$pass,$date){
       
$mysqli = new Class_Connection('<dbHost>','<username>','<password>','<database>');
       
$query = "CALL insertUserdata(". $id .",'". $name ."','". $email ."','". $pass ."','". $date ."')";
      
        if (
$mysqli->multi_query($query)) {
            print
"Mission Complete";
          
        }
      
    }
}
?>

index.php

/*
* call Storeprocedure fuction (index.php)
*/
<?php
require_once('Data.php');
 
DAO_data::SP_insertData(1005,'My Test User','MyTest@Test.Com','password','11/11/11');
$data = DAO_data::SP_getData();
print_r($data)

?>
Tags: 
X