Source for file mysqli.dbstatement.php

Documentation is available at mysqli.dbstatement.php

  1. <?php
  2. /**
  3. * @package    jelix
  4. * @subpackage db_driver
  5. * @author      Florian Lonqueu-Brochard
  6. * @contributor Laurent Jouanneau
  7. * @copyright  2012 Florian Lonqueu-Brochard, 2012 Laurent Jouanneau
  8. * @link      http://www.jelix.org
  9. * @licence    http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  10. */
  11.  
  12. require_once(__DIR__.'/mysqli.dbresultset.php');
  13.  
  14. class mysqliDbStatement extends jDbStatement {
  15.  
  16.     private $_usesMysqlnd = true;
  17.  
  18.     function __construct($connection, $usesMysqlnd){
  19.         $this->_usesMysqlnd = $usesMysqlnd;
  20.         parent::__construct($connection);
  21.     }
  22.  
  23.     public function execute(){
  24.         $this->_stmt->execute();
  25.  
  26.         if($this->_stmt->result_metadata()){
  27.             //the query prodeces a result
  28.             try{
  29.                 if( $this->_usesMysqlnd ) {
  30.                     //with the MySQL native driver - mysqlnd (by default in php 5.3.0)
  31.                     $res = new mysqliDbResultSet($this->_stmt->get_result());
  32.                 } else {
  33.                     $res = new mysqliDbStmtResultSet($this->_stmt);
  34.                 }
  35.             }
  36.             catch(Exception $e){
  37.                 throw new jException('jelix~db.error.query.bad', $this->_stmt->errno);
  38.             }
  39.         }
  40.         else{
  41.             if($this->_stmt->affected_rows > 0) {
  42.                 $res = $this->_stmt->affected_rows;
  43.             }
  44.             elseif ($this->_stmt->affected_rows === null) {
  45.                 throw new jException('jelix~db.error.invalid.param');
  46.             }
  47.             else{
  48.                 throw new jException('jelix~db.error.query.bad', $this->_stmt->errno);
  49.             }
  50.         }
  51.         return $res;
  52.     }
  53.  
  54.     /**
  55.      * @see http://www.php.net/manual/fr/mysqli-stmt.bind-param.php
  56.      */
  57.     public function bindParam(){
  58.         $args = func_get_args();
  59.         $method = new ReflectionMethod('mysqli_stmt', 'bind_param');
  60.         $res = $method->invokeArgs($this->_stmt, $args); 
  61.         if(!$res){
  62.             throw new jException('jelix~db.error.invalid.param');
  63.         }
  64.         return $res;
  65.     }
  66.  
  67.  
  68.     protected function _free(){
  69.         return $this->_stmt->close();
  70.     }
  71.  
  72.  
  73.     public function getAttribute($attr){
  74.         return $this->_stmt->get_attr($attr);
  75.     }
  76.  
  77.     public function setAttribute($attr, $value){
  78.         return $this->_stmt->get_attr($attr, $value);
  79.     }
  80. }

Documentation generated on Wed, 04 Jan 2017 22:58:19 +0100 by phpDocumentor 1.4.3