开发者

Zend_Db_Adapter_Mysqli::fetchAssoc() I don't want primary keys as array indexes!

According to ZF documentation when using fetchAssoc() the first column in the result set must contain unique values, or else rows with duplicate values in the first column will overwrite previous data.

I don't want this, I want my array to be indexed 0,1,2,3... I don't need rows to be unique because I won't modify them and wo开发者_运维知识库n't save them back to the DB.


According to ZF documentation fetchAll() (when using the default fetch mode, which is in fact FETCH_ASSOC) is equivalent to fetchAssoc(). BUT IT'S NOT. I've used print_r()function to reveal the truth.

print_r($db->fetchAll('select col1, col2 from table'));

prints

Array
(
    [0] => Array
        (
            [col1] => 1
            [col2] => 2
        )
)

So:

  1. fetchAll() is what I wanted.
  2. There's a bug in ZF documentation


From http://framework.zend.com/manual/1.11/en/zend.db.adapter.html The fetchAssoc() method returns data in an array of associative arrays, regardless of what value you have set for the fetch mode, **using the first column as the array index**.

So if you put
$result = $db->fetchAssoc(
'SELECT some_column, other_column FROM table'
);

you'll have as result an array like this

$result['some_column']['other_column']

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜