不能使用函数返回值

Dzo*_*oki -3 php mysql sql mysqli

我只是不明白问题在哪里,但这里是错误:

致命错误:无法在第70行的D:\ wamp\www\system\classes\database.class.php中的写入上下文中使用函数返回值

码:

public function query($sql) {
        if(!is_string() or empty(trim($sql))) {
            throw new Exception('No sql statement was entered.');
        }

        $query = @mysql_query($sql);

        if(!$query) {
            throw new Exception('Query could not be executed because of an error: [#' . mysql_errno() . '] - ' . mysql_error());
        }

        return $query;
    }
Run Code Online (Sandbox Code Playgroud)

第70行:

 if(!is_string() or empty(trim($sql))) {
Run Code Online (Sandbox Code Playgroud)

dev*_*odo 8

它就在空函数的手册中:http://php.net/empty

empty()只检查变量,因为其他任何东西都会导致解析错误.换句话说,以下内容不起作用:empty(trim($ name)).

要修复它,您需要执行以下操作:

$sql = trim($sql);
if(!is_string() or empty($sql)) {
...
}
Run Code Online (Sandbox Code Playgroud)

  • +1可能是最明显的答案,有史以来最好的参考. (2认同)