I recognize this is an old thread, so I'm posting this answer here because I had the same issue today, and couldn't find a solution anywhere. I'll note I'm a relative novice to PHP. I ran into this issue converting a Cakephp 1.2 app from Mysql to Postgres. There are several instances of the "query" method, which returned zero-indexed arrays, like yours, instead of the table-name indices that the app was built to utilize. The cake 1.2 docs states that the array structuring of query results only works for Mysql, and may vary for different DB types. Bummer! I was afraid I'd have to modify hundreds of hard-coded queries to make my app work again. (I didn't build it, by the way - I was just tasked with converting it) Since I couldn't find a solution, I just dug around a little through Cake's dbo files, and added some lines that solved my problem:
To 'appname/cake/libs/model/datasources/dbo/dbo_postgres.php' I modified the 'resultSet' method. I changed this: > while ($j < $num_fields) { > $columnName = pg_field_name($results, $j); > if (strpos($columnName, '__')) { > $parts = explode('__', $columnName); > $this->map[$index++] = array($parts[0], $parts[1]); > } else { > $this->map[$index++] = array(0, $columnName); > } > $j++; > } To include a new "else if" condition: while ($j < $num_fields) { > $columnName = pg_field_name($results, $j); > * $tableName = pg_field_table($results, $j); > * if (strpos($columnName, '__')) { > $parts = explode('__', $columnName); > $this->map[$index++] = array($parts[0], $parts[1]); > } *elseif ($tableName != 'columns' && $tableName != 'tables') { > $tableName = pg_field_table($results, $j); > $this->map[$index++] = array($tableName, $columnName);* > } else { > $this->map[$index++] = array(0, $columnName); > } > $j++; > } Basically, it was previously returning a zero-indexed array because it wasn't grabbing the table name. This new condition grabs the table name, and uses it as the array index, as is the default behaviour of the Mysql dbo. This worked for me, eliminating any need to change the previously working code. The bigger issue with the app I'm working on is that there shouldn't be so many hard-coded queries in there to begin with, but that's an issue for another, longer day. On Thursday, April 15, 2010 12:30:11 AM UTC-4, Adam wrote: > > When I do a find and get 1 row back in Postgres it has to be > referenced like $data[0][email] whereas in Mysql you can do > $data[Account][email]. > > I just migrated from Mysql to Postgres so I just have to go thru and > change all single result queries that formerly worked in Mysql as > $data[Account][email] to $data[0][email] in Postgres. > > Or is there something I'm doing wrong here? > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.