UnionOfRAD/lithium — Issue #231: Relationships piggybacking is broken since switch to PDO
Author: greut
Created: 2012-01-01 17:47:42+00:00
State: open

# What happens

I was trying to load data using `with` and hit this wall:

Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements in /home/yoan/Work/BikiniTest/www/libraries/lithium/data/collection/RecordSet.php on line 347

It happens because it tries to create the related object with not enough fields (because I have name collisions in my models using id, created_at and updated_at everywhere).

# The cause

If you take a look at this commit:

https://github.com/UnionOfRAD/lithium/commit/89b7435f638443a5c2484038be6fd824a7242ed2

You can see that [`mysql_fetch_row`](http://ch2.php.net/manual/en/function.mysql-fetch-row.php) was used and has been replaced by [`PDOStatement::fetch(PDO::FETCH_ASSOC)`](http://ch2.php.net/manual/en/pdostatement.fetch.php).

`mysql_fetch_row` really is `PDO::FETCH_NUM`.

# How (and where) to fix

```diff
diff --git a/data/source/database/adapter/my_sql/Result.php b/data/source/database/adapter/my_sql/Result.php
index 1d0b46a..667f73a 100644
--- a/data/source/database/adapter/my_sql/Result.php
+++ b/data/source/database/adapter/my_sql/Result.php
@@ -98,7 +98,7 @@ class Result extends \lithium\core\Object implements \Iterator {
protected function _fetchFromResource() {
if ($this->_resource instanceof PDOStatement
&& $this->_iterator < $this->_resource->rowCount()
- && $result = $this->_resource->fetch(PDO::FETCH_ASSOC)) {
+ && $result = $this->_resource->fetch(PDO::FETCH_NUM)) {

$this->_iterator++;
$this->_maxIteration = $this->_iterator;
```

kthxbai