【问题标题】:Update "mysql_fetch_array" to "$wpdb->get_results" in wordpress plugin在 wordpress 插件中将“mysql_fetch_array”更新为“$wpdb->get_results”
【发布时间】:2016-02-13 16:53:48
【问题描述】:

我正在更新一些旧的 wordpress 插件文件,并且知道我需要将“mysql_fetch_array”更新为“$wpdb->get_results”以使插件与数据库对话。

这里是使用“mysql_fetch_array”的代码:

//select ads id's  stored into db table
$sql  = "SELECT id FROM $table_name_ad_google";
$result = mysql_query($sql);

while($row = mysql_fetch_array($result))
{

如何重写它以使用 $wpdb->get_results?

【问题讨论】:

  • $result = $wpdb->get_results($sql);这返回一个对象。还不够?
  • 由于你只对一个领域感兴趣,你也可以使用$wpdb->get_col:$ids = $wpdb->get_col('SELECT id FROM '.$table_name_ad_google);

标签: php mysql wordpress plugins


【解决方案1】:
$sql = "SELECT * FROM tbl_employee WHERE 1=1";
$query = $wpdb->get_results($sql,ARRAY_A);
foreach($query as $row){
/*$row["your column name"];*/
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多