我正在将一个具有直接MySQL访问权限的脚本迁移到$wpdb类,但它失败了。下面是相邻的原始代码和新代码。怎么了?
<!--
##############################################################################
PART 1: OLD MYSQL FUNCTIONS
-->
<?php
function get_tag_data2() {
$result = mysql_query("SELECT * FROM ( SELECT lastname, count( lastname ) AS mycount FROM `tng_people` GROUP BY lastname ORDER BY count( lastname ) DESC LIMIT 0 , 35) AS presort order by rand()");
while($row = mysql_fetch_array($result)) {
$arr[$row[\'lastname\']] = $row[\'mycount\'];
}
return $arr;
}
?>
<!--
##############################################################################
PART 2: NEW WPDB FUNCTIONS
-->
<?php
global $wpdb;
function get_tag_data2() {
$tngnameresults = $wpdb->get_results("SELECT * FROM ( SELECT lastname, count( lastname ) AS mycount FROM `tng_people` GROUP BY lastname ORDER BY count( lastname ) DESC LIMIT 0 , 10) AS presort order by rand()");
$arr = array();
foreach ($tngnameresults as $result) {
$arr[$result->lastname] = $result->mycount;
}
return $arr;
}
?>