I\'m running a MySQL query via a command-line PHP script (prepared query using PDO on the mysqlnd driver). It\'s a simple query with a single left-join, returning 100 rows
I had the same problem. Same query was acting differently when launched from cli and from PHP. Explain in cli mentioned correct index usage, in PHP there was nothing. As I have found, the problem was type casting, in my case it was datetime. After I have specifically cast type for compared value eg. where datetime_column > cast('2014-01-12 12:30:01' as datetime)
everything works.