首页 > 解决方案 > PHP 未捕获错误:在 null 上调用成员函数 escape_value()

问题描述

我收到此错误:

未捕获的错误:在 /opt/bitnami/nginx/html/blog/assets/includes/Library/Misc.php:15 中调用成员函数 escape_value()

这是第 15 行:

public static function get_function($func="") {
    global $db;
    $result_array =  self::preform_sql("SELECT * FROM " . DBTP . self::$table_name . " WHERE function = '" . $db->escape_value($func) . "' LIMIT 1");
    return !empty($result_array) ? array_shift($result_array) : false;
}

我该如何解决这个问题?

标签: php

解决方案


global $db;
//add this to check $db
if (empty($db)) { //better to use instanceof function
    return null; //or do something your: show error | throw exception | else
}

推荐阅读