amphp / mysql

An async MySQL client for PHP, optimizing database interactions with efficient non-blocking capabilities. Perfect for responsive, high-performance applications.
Other
358 stars 63 forks source link

Sort binary result sets correctly #121

Closed bennnjamin closed 2 years ago

bennnjamin commented 2 years ago

So this pull request doesn't have to be merged as there might be a better way to handle this, but essentially due to the way packet is parsed, the columns are out of order only when the result set contains null columns. Since PHP arrays are always ordered based on insertion order (they are basically just maps), this line https://github.com/amphp/mysql/blob/56a5a9c54ec21e88a8db257aed88c8cceceb3a12/src/Internal/ConnectionProcessor.php#L1137 doesn't do what it intends to do. PHP arrays are ordered based on insertion order, so all null columns are always at the beginning of the result row.

This change just sorts the array keys using ksort. It's a brute fix.

trowski commented 2 years ago

Thanks! Seems ksort is there in v2, so I must have inadvertently deleted it sometime when refactoring for v3.