コード例 #1
0
ファイル: SqlsrvTest.php プロジェクト: vicfryzel/zf
 public function testStatementErrorInfo()
 {
     $products = $this->_db->quoteIdentifier('zfproducts');
     $product_id = $this->_db->quoteIdentifier('product_id');
     $query = "INVALID SELECT * FROM INVALID TABLE WHERE {$product_id} > 1 ORDER BY {$product_id} ASC";
     $stmt = new Zend_Db_Statement_Sqlsrv($this->_db, $query);
     try {
         $stmt->fetchAll();
         $this->fail("Invalid query should have throw an error");
     } catch (Zend_Db_Statement_Sqlsrv_Exception $e) {
         // Exception is thrown, nothing to worry about
         $this->assertEquals(-11, $e->getCode());
     }
     $this->assertNotSame(false, $stmt->errorCode());
     $this->assertEquals(-11, $stmt->errorCode());
     $errors = $stmt->errorInfo();
     $this->assertEquals(2, count($errors));
     $this->assertEquals($stmt->errorCode(), $errors[0]);
     $this->assertType('string', $errors[1]);
 }
コード例 #2
0
 /**
  * Fetches a row from the result set.
  *
  * @param  int $style  OPTIONAL Fetch mode for this fetch operation.
  * @param  int $cursor OPTIONAL Absolute, relative, or other.
  * @param  int $offset OPTIONAL Number for absolute or relative cursors.
  * @return mixed Array, object, or scalar depending on fetch mode.
  * @throws Zend_Db_Statement_Exception
  */
 public function fetch($style = null, $cursor = null, $offset = null)
 {
     try {
         $result = parent::fetch($style, $cursor, $offset);
     } catch (Zend_Db_Statement_Sqlsrv_Exception $e) {
         if ($e->getCode() == -22) {
             return false;
         }
         throw $e;
     }
     if ($result === null) {
         return false;
     }
     return $result;
 }