php - mysql results with ORDER & LIMIT non english character fail

大兔子大兔子 提交于 2019-12-23 05:37:07

问题


I have a simple mysql query in a php function (wordpress).

The function works with no problem, except when the result is with non English characters ( or non Latin) e.g. Hebrew, Arab, Chinese, Japanese...

The thing is , that the query works just fine if I remove the ORDER BY and the LIMIT commands. (see commented out in the code).

 $keys = $wpdb->get_col( "
                SELECT meta_key
                FROM $wpdb->postmeta
                GROUP BY meta_key
                " . $hide_underscore . "
                /* ORDER BY meta_key 
                LIMIT $limit */
                " );
if ( $keys )
            natcasesort($keys);

The keys themselves (meta_key) exist in the DB just fine, and other functions or query have no problem whatsoever using them (so it is not a locale, DB encoding , or character set problem..) also the natcasesort() function does not seem to be the problem ..

It looks like it is a specific problem of the ORDER and / or LIMIT.

Is there a reason why just those commands are failing ? is there a solution ?

I have tried to remove (comment out) only ONE of the pair , but it still fails. only removing both will work.

UPDATE I

I forgot to mention

$hide_underscore ='HAVING meta_key NOT LIKE "\_%"'

or

$hide_underscore =''

来源:https://stackoverflow.com/questions/14452324/php-mysql-results-with-order-limit-non-english-character-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!