Database query returns unexpected keys
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
PHPDevShell |
Invalid
|
Undecided
|
Unassigned |
Bug Description
Ok, try the following:
Given this database table:
CREATE TABLE pds_test (
id int(11) NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=
INSERT INTO pds_test (id, `name`) VALUES
(2, 'Bob'),
(4, 'Jeff');
And this controller test.php:
<?php
class test extends PHPDS_controller
{
public function execute()
{
$test = $this->
echo '<pre>';
print_r($test);
echo '</pre>';
}
}
return 'test';
And this model:
<?php
class myPlugin_test extends PHPDS_query
{
protected $sql = "
SELECT *
FROM _db_test
";
}
This returns the following results:
Array
(
[2] => Array
(
[id] => 2
[name] => Bob
)
[4] => Array
(
[id] => 4
[name] => Jeff
)
)
I would have expected the results of the main key to start with an index of 0 (see below) and not with the [id] field:
Array
(
[0] => Array
(
[id] => 2
[name] => Bob
)
[1] => Array
(
[id] => 4
[name] => Jeff
)
)
Changed in phpdevshell: | |
status: | New → Invalid |
Ok, after looking into this further, I am seeing that setting the data query switch to $keyField=false will cause the result keys to returned as a numeric array starting at index[0].
In my opinion, this should be the default behavior.
So I would suggest that default behavior, when not specified, is $keyField=false and not $keyField= '__auto_ _'