【问题标题】:Php query over wordpress db doesn't work通过 wordpress db 的 PHP 查询不起作用
【发布时间】:2018-12-28 04:48:29
【问题描述】:

我尝试从名为 test.php 的独立 php 文件中查询 wordpress 数据库,该文件位于 wp 安装文件夹的根文件夹中,但是查询没有返回要显示的内容,var 转储没有显示,我做错了什么以及如何测试主机是否支持 mysqli?(凭据已从数据库连接中删除) enter image description here

<?php

$mysqli = new mysqli('localhost', 'username', 'passwd', 'dbname');

/* check connection */
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

/* Select queries return a resultset */
$result = $mysqli->query("select meta_value from wpde_postmeta where meta_key = '_product_attributes' and post_id = '41'") ;
    echo $result;
  var_dump($result);

    /* free result set */
    $result->close();
$mysqli->close();
?>

【问题讨论】:

  • 所以我认为 post_id 41 存在?不得不问,有时候就是这么简单……

标签: php mysql wordpress mysqli


【解决方案1】:

您缺少数据获取部分:

// Just below $result = $mysqli->query("...") ;

while($obj = $result->fetch_object()){ 
    // Do something with $obj->meta_value
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-07
    • 2013-09-29
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    • 2014-02-12
    • 1970-01-01
    相关资源
    最近更新 更多