• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/Db/Statement/Db2.php

00001 <?php
00026 require_once 'Zend/Db/Statement.php';
00027 
00036 class Zend_Db_Statement_Db2 extends Zend_Db_Statement
00037 {
00038 
00042     protected $_keys;
00043 
00047     protected $_values;
00048 
00056     public function _prepare($sql)
00057     {
00058         $connection = $this->_adapter->getConnection();
00059 
00060         // db2_prepare on i5 emits errors, these need to be
00061         // suppressed so that proper exceptions can be thrown
00062         $this->_stmt = @db2_prepare($connection, $sql);
00063 
00064         if (!$this->_stmt) {
00068             require_once 'Zend/Db/Statement/Db2/Exception.php';
00069             throw new Zend_Db_Statement_Db2_Exception(
00070                 db2_stmt_errormsg(),
00071                 db2_stmt_error()
00072             );
00073         }
00074     }
00075 
00087     public function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
00088     {
00089         if ($type === null) {
00090             $type = DB2_PARAM_IN;
00091         }
00092 
00093         if (isset($options['data-type'])) {
00094             $datatype = $options['data-type'];
00095         } else {
00096             $datatype = DB2_CHAR;
00097         }
00098 
00099         if (!db2_bind_param($this->_stmt, $position, "variable", $type, $datatype)) {
00103             require_once 'Zend/Db/Statement/Db2/Exception.php';
00104             throw new Zend_Db_Statement_Db2_Exception(
00105                 db2_stmt_errormsg(),
00106                 db2_stmt_error()
00107             );
00108         }
00109 
00110         return true;
00111     }
00112 
00118     public function closeCursor()
00119     {
00120         if (!$this->_stmt) {
00121             return false;
00122         }
00123         db2_free_stmt($this->_stmt);
00124         $this->_stmt = false;
00125         return true;
00126     }
00127 
00128 
00135     public function columnCount()
00136     {
00137         if (!$this->_stmt) {
00138             return false;
00139         }
00140         return db2_num_fields($this->_stmt);
00141     }
00142 
00149     public function errorCode()
00150     {
00151         if (!$this->_stmt) {
00152             return false;
00153         }
00154 
00155         $error = db2_stmt_error();
00156         if ($error === '') {
00157             return false;
00158         }
00159 
00160         return $error;
00161     }
00162 
00169     public function errorInfo()
00170     {
00171         $error = $this->errorCode();
00172         if ($error === false){
00173             return false;
00174         }
00175 
00176         /*
00177          * Return three-valued array like PDO.  But DB2 does not distinguish
00178          * between SQLCODE and native RDBMS error code, so repeat the SQLCODE.
00179          */
00180         return array(
00181             $error,
00182             $error,
00183             db2_stmt_errormsg()
00184         );
00185     }
00186 
00194     public function _execute(array $params = null)
00195     {
00196         if (!$this->_stmt) {
00197             return false;
00198         }
00199 
00200         $retval = true;
00201         if ($params !== null) {
00202             $retval = @db2_execute($this->_stmt, $params);
00203         } else {
00204             $retval = @db2_execute($this->_stmt);
00205         }
00206 
00207         if ($retval === false) {
00211             require_once 'Zend/Db/Statement/Db2/Exception.php';
00212             throw new Zend_Db_Statement_Db2_Exception(
00213                 db2_stmt_errormsg(),
00214                 db2_stmt_error());
00215         }
00216 
00217         $this->_keys = array();
00218         if ($field_num = $this->columnCount()) {
00219             for ($i = 0; $i < $field_num; $i++) {
00220                 $name = db2_field_name($this->_stmt, $i);
00221                 $this->_keys[] = $name;
00222             }
00223         }
00224 
00225         $this->_values = array();
00226         if ($this->_keys) {
00227             $this->_values = array_fill(0, count($this->_keys), null);
00228         }
00229 
00230         return $retval;
00231     }
00232 
00242     public function fetch($style = null, $cursor = null, $offset = null)
00243     {
00244         if (!$this->_stmt) {
00245             return false;
00246         }
00247 
00248         if ($style === null) {
00249             $style = $this->_fetchMode;
00250         }
00251 
00252         switch ($style) {
00253             case Zend_Db::FETCH_NUM :
00254                 $row = db2_fetch_array($this->_stmt);
00255                 break;
00256             case Zend_Db::FETCH_ASSOC :
00257                 $row = db2_fetch_assoc($this->_stmt);
00258                 break;
00259             case Zend_Db::FETCH_BOTH :
00260                 $row = db2_fetch_both($this->_stmt);
00261                 break;
00262             case Zend_Db::FETCH_OBJ :
00263                 $row = db2_fetch_object($this->_stmt);
00264                 break;
00265             case Zend_Db::FETCH_BOUND:
00266                 $row = db2_fetch_both($this->_stmt);
00267                 if ($row !== false) {
00268                     return $this->_fetchBound($row);
00269                 }
00270                 break;
00271             default:
00275                 require_once 'Zend/Db/Statement/Db2/Exception.php';
00276                 throw new Zend_Db_Statement_Db2_Exception("Invalid fetch mode '$style' specified");
00277                 break;
00278         }
00279 
00280         return $row;
00281     }
00282 
00290     public function fetchObject($class = 'stdClass', array $config = array())
00291     {
00292         $obj = $this->fetch(Zend_Db::FETCH_OBJ);
00293         return $obj;
00294     }
00295 
00304     public function nextRowset()
00305     {
00309         require_once 'Zend/Db/Statement/Db2/Exception.php';
00310         throw new Zend_Db_Statement_Db2_Exception(__FUNCTION__ . '() is not implemented');
00311     }
00312 
00320     public function rowCount()
00321     {
00322         if (!$this->_stmt) {
00323             return false;
00324         }
00325 
00326         $num = @db2_num_rows($this->_stmt);
00327 
00328         if ($num === false) {
00329             return 0;
00330         }
00331 
00332         return $num;
00333     }
00334 
00346     public function fetchAll($style = null, $col = null)
00347     {
00348         $data = parent::fetchAll($style, $col);
00349         $results = array();
00350         $remove = $this->_adapter->foldCase('ZEND_DB_ROWNUM');
00351 
00352         foreach ($data as $row) {
00353             if (is_array($row) && array_key_exists($remove, $row)) {
00354                 unset($row[$remove]);
00355             }
00356             $results[] = $row;
00357         }
00358         return $results;
00359     }
00360 }

Generated on Thu Apr 19 2012 17:01:17 for openbiz by  doxygen 1.7.2