{"action":"closed","issue":{"url":"https://api.github.com/repos/zendframework/zendframework/issues/4984","repository_url":"https://api.github.com/repos/zendframework/zendframework","labels_url":"https://api.github.com/repos/zendframework/zendframework/issues/4984/labels{/name}","comments_url":"https://api.github.com/repos/zendframework/zendframework/issues/4984/comments","events_url":"https://api.github.com/repos/zendframework/zendframework/issues/4984/events","html_url":"https://github.com/zendframework/zendframework/issues/4984","id":18207515,"number":4984,"title":"Zend\\Db\\Adapter\\Driver\\Mysqli\\Statement::bindParametersFromContainer bug","user":{"login":"coud","id":4945814,"avatar_url":"https://avatars.githubusercontent.com/u/4945814?v=3","gravatar_id":"","url":"https://api.github.com/users/coud","html_url":"https://github.com/coud","followers_url":"https://api.github.com/users/coud/followers","following_url":"https://api.github.com/users/coud/following{/other_user}","gists_url":"https://api.github.com/users/coud/gists{/gist_id}","starred_url":"https://api.github.com/users/coud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coud/subscriptions","organizations_url":"https://api.github.com/users/coud/orgs","repos_url":"https://api.github.com/users/coud/repos","events_url":"https://api.github.com/users/coud/events{/privacy}","received_events_url":"https://api.github.com/users/coud/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/zendframework/zendframework/labels/Db","name":"Db","color":"008000"},{"url":"https://api.github.com/repos/zendframework/zendframework/labels/To%20Be%20Closed","name":"To Be Closed","color":"eb6420"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2013-08-18T13:39:21Z","updated_at":"2016-06-27T19:32:52Z","closed_at":"2016-06-27T19:32:52Z","body":"I stumbled upon with this bug while I'm working with pivot tables with subselect. I deduced the bug to the simplest test.\r\n\r\nDatabase table structure. I named it 'tbldata'\r\n\r\nid  | data\r\n----+---------\r\n1   | data1\r\n2   | data2\r\n3   | data3\r\n\r\nHere's the test\r\n\r\n```php\r\nuse Zend\\Db\\Adapter\\Adapter;\r\nuse Zend\\Db\\Sql\\Sql;\r\nuse Zend\\Db\\Sql\\Expression;\r\n\r\n$adapter = new Adapter($someOptions);\r\n\r\n$subselect = $sql->select('tbldata');\r\n$subselect->columns(array(\r\n    'id',\r\n    'data'\r\n));\r\n$subselect->where(array(\r\n    'id' => array(1,2,3)\r\n));\r\n\r\n$select = $sql->select(array(\r\n    't' => $subselect\r\n));\r\n$select->columns(array(\r\n    'id',\r\n    'data',\r\n    'explicit1' => new Expression('?', 'value1', array(\r\n        Expression::TYPE_VALUE\r\n    )),\r\n    'explicit2' => new Expression('?', 'value2', array(\r\n        Expression::TYPE_VALUE\r\n    ))\r\n));\r\n\r\n\r\n$stmt = $sql->prepareStatementForSqlObject($select);\r\n$result = $stmt->execute();\r\n\r\nprint_r(ArrayUtils::iteratorToArray($result)); \r\nthis outputs the following:\r\n\r\nArray\r\n(\r\n    [1] => Array\r\n        (\r\n            [id] => 3\r\n            [data] => data3\r\n            [explicit1] => 1\r\n            [explicit2] => 2\r\n        )\r\n\r\n)\r\n```\r\nIt's wrong right?\r\nThe expected result should be:\r\n```\r\nArray\r\n(\r\n    [1] => Array\r\n        (\r\n            [id] => 1\r\n            [data] => data1\r\n            [explicit1] => value1\r\n            [explicit2] => value2\r\n        )\r\n\r\n    [2] => Array\r\n        (\r\n            [id] => 2\r\n            [data] => data2\r\n            [explicit1] => value1\r\n            [explicit2] => value2\r\n        )\r\n\r\n    [3] => Array\r\n        (\r\n            [id] => 3\r\n            [data] => data3\r\n            [explicit1] => value1\r\n            [explicit2] => value2\r\n        )\r\n\r\n)\r\n```\r\nThen I output the sql with code $sql->prepareSqlStringForObject($select); The output is as what expected:\r\n```\r\nSELECT `t`.`id` AS `id`, `t`.`data` AS `data`, 'value1' AS `explicit1`, 'value2' AS `explicit2` FROM (SELECT `tbldata`.`id` AS `id`, `tbldata`.`data` AS `data` FROM `tbldata` WHERE `id` IN ('1', '2', '3')) AS `t`\r\n```\r\nAnd then I tested the sql with the other method:\r\n```\r\n$stmt = $adapter->getDriver()->createStatement($sql->getSqlStringForSqlObject($select));\r\n$result = $stmt->execute();\r\n```\r\nand the result is correct same as the expected result above.\r\n\r\nI dug into execute command and found it that the ordering of parameters is wrong in bindParametersFromContainer in Mysqli\\Statement\r\n\r\nSee debugger screenshot:\r\n![args](https://f.cloud.github.com/assets/4945814/982614/4ba5b91c-080b-11e3-9529-37ccd37ee598.jpg)\r\n\r\nSee variables panel the args is in different order compare to the sql parameters\r\n![sql](https://f.cloud.github.com/assets/4945814/982618/8799141e-080b-11e3-8293-c65dc7bef26b.jpg)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"GeeH"}}