Zend_db & SQL SERVER & Procédure stockée

Voici un bout de code permettant d’exécuter une procédure stockée MS SQL SERVER à partir de Zend DB :

Fichier config.ini :

 [[database]]
 driver   = Pdo_Mssql
 host   = x.x.x.x
 type   = dblib ; sous linux (avec freetds d'installé) sinon mssql sur Windows
 username  = y
 password  = z

Fichier test.php :
 
  $config = new Zend_Config_Ini('./conf/config.ini',null); 
 
  $params = array(
  'host'  =>$GLOBALS[['config']]->database->host,
  'pdoType'              =>$GLOBALS[['config']]->database->type,
  'dbname'              =>$GLOBALS[['config']]->database->dbname,
  'username' =>$GLOBALS[['config']]->database->username,
  'password' =>$GLOBALS[['config']]->database->password   
  );
      
  $db = Zend_Db::factory($GLOBALS[['config']]->database->driver, $params);  
    
  $param1 = "hello";
  $param2 = "world";
    
  $stmt = $db->prepare("sp_show_texte ?,?");
  $stmt->bindParam(1, $param1, PDO::PARAM_STR, 25);
  $stmt->bindParam(2, $param2, PDO::PARAM_STR, 25);
  $res = $stmt->execute(); 
 
  echo $res; // code retour de l'exécution       
  print_r($stmt->fetchAll()); // enregistrement(s) retourné(s)
          
  $db->closeConnection();

You can leave a response, or trackback from your own site.

Leave a Reply

Powered by WordPress | iCellPhoneDeals.com has the best cell phone Deals. | Thanks to Upgrade Sprint Phone, MMO Games and Conveyancing