Browse Source

ZF-5675: changed Mysqli statement to return boolean FALSE on an empty record set

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18192 44c647ce-9c0f-0410-b52a-842ac1e357ba
bittarman 16 years ago
parent
commit
2c9674d949
2 changed files with 20 additions and 6 deletions
  1. 6 6
      library/Zend/Db/Statement/Mysqli.php
  2. 14 0
      tests/Zend/Db/Statement/MysqliTest.php

+ 6 - 6
library/Zend/Db/Statement/Mysqli.php

@@ -275,12 +275,12 @@ class Zend_Db_Statement_Mysqli extends Zend_Db_Statement
         // fetch the next result
         $retval = $this->_stmt->fetch();
         switch ($retval) {
-        case null: // end of data
-        case false: // error occurred
-            $this->_stmt->reset();
-            return $retval;
-        default:
-            // fallthrough
+	        case null: // end of data
+	        case false: // error occurred
+	            $this->_stmt->reset();
+	            return false;
+	        default:
+	            // fallthrough
         }
 
         // make sure we have a fetch mode

+ 14 - 0
tests/Zend/Db/Statement/MysqliTest.php

@@ -132,6 +132,20 @@ class Zend_Db_Statement_MysqliTest extends Zend_Db_Statement_TestCommon
         $this->assertType('mysqli_stmt', $statement->getDriverStatement());
     }
     
+    /**
+     * Tests that the statement returns FALSE when no records are found
+     * @group ZF-5675
+     */
+    public function testStatementReturnsFalseOnEmpty()
+    {
+    	$products = $this->_db->quoteIdentifier('zfproducts');
+    	$sql = 'SELECT * FROM ' . $products . ' WHERE 1=2';
+        $stmt = $this->_db->query($sql);
+        $result = $stmt->fetch();
+        $this->assertFalse($result);
+    }
+    
+    
     public function getDriver()
     {
         return 'Mysqli';