PHP和MYSQL:将结果作为对象获取时,fetch_object()不起作用

时间:2019-01-17 02:45:53

标签: php mysqli

我试图用fetch_object创建函数。代码未运行并返回错误 PHP致命错误:在布尔值上调用成员函数fetch_object()

下面是供您查看的代码:


function get_result($res, $mth, $proj) {
    $db = new mysqli(DB_SERVER,DB_UID,DB_PWD,DB_USEDB) or die(mysqli_connect_error());
    if ($res == 'atput') {
        if ($proj == 'fb') {
            $stmt = "SELECT sum(atput) as atput FROM dsp WHERE dsp.mth=$mth and dsp.proj not in ('fjb','fgt','lb','ptps')";
        }
        else {
            $stmt = "SELECT dsp.atput FROM dsp WHERE dsp.mth=$mth and dsp.proj='$proj'";
        }    
        $q = $db->query($stmt);
        $r = $q->fetch_object();
        return $r->atput;
    }
}

0 个答案:

没有答案