Commit a8f66a29 authored by Steve Müller's avatar Steve Müller

Merge pull request #755 from gohanman/mysqli-pdo-fetch-obj

Update MysqliStatement to support PDO::FETCH_OBJ

Close #755
parents b17992b5 57379036
......@@ -264,6 +264,16 @@ class MysqliStatement implements \IteratorAggregate, Statement
return $ret;
case PDO::FETCH_OBJ:
$assoc = array_combine($this->_columnNames, $values);
$ret = new \stdClass();
foreach ($assoc as $column => $value) {
$ret->$column = $value;
}
return $ret;
default:
throw new MysqliException("Unknown fetch type '{$fetchMode}'");
}
......
......@@ -641,6 +641,43 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->assertEquals(0, count( array_filter($row, function($v) { return ! is_numeric($v); })), "should be no non-numerical elements in the result.");
}
/**
* @group DBAL-1091
*/
public function testFetchAllStyleObject()
{
$driverName = $this->_conn->getDriver()->getName();
if (in_array($driverName, array('oci8'), true)) {
$this->markTestSkipped(sprintf('Driver "%s" does not support hydrating data to an object.', $driverName));
}
$this->setupFixture();
$sql = 'SELECT test_int, test_string, test_datetime FROM fetch_table';
$stmt = $this->_conn->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(\PDO::FETCH_OBJ);
$this->assertCount(1, $results);
$this->assertInstanceOf('stdClass', $results[0]);
$this->assertEquals(
1,
property_exists($results[0], 'test_int') ? $results[0]->test_int : $results[0]->TEST_INT
);
$this->assertEquals(
'foo',
property_exists($results[0], 'test_string') ? $results[0]->test_string : $results[0]->TEST_STRING
);
$this->assertStringStartsWith(
'2010-01-01 10:10:10',
property_exists($results[0], 'test_datetime') ? $results[0]->test_datetime : $results[0]->TEST_DATETIME
);
}
/**
* @group DBAL-196
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment