我从未在 php 中使用过新的 mysqli 类,因为旧的 mysql 接口总是足够好,但是我正在尝试更新一些旧代码以使用 mysqli,但事情进展并不顺利,我收到以下错误:
[error] [client 127.0.0.1] PHP Fatal error: Call to a member function fetch_row() on a non-object in [location of file]
但是我知道查询很好,因为我可以回显它并直接在数据库上使用它来给我很好的结果。我有一种感觉,我错误地使用了“fetch_row()。
有人可以建议我做错了什么吗?
/// class setup stuff
public function query($query,$sanitize=TRUE)
{
if($sanitize!==FALSE)
{
$query=$this->mysqli->escape_string($query);
}
echo $query;
$this->mysqli->query($query);
echo $this->mysqli->error;
//$this->mysqli->free();
}
public function select($table,$what,$where,$orderby=FALSE,$order=FALSE,$limits=FALSE,$sanitize=TRUE) //this is really simple and very limited
{
//process the select query and send to query method
$query = "SELECT $what FROM $table WHERE ";
$i = 0;
foreach($where as $key => $value)
{
$key = $sanitize?$this->mysqli->escape_string($key):$key;
$value = $sanitize?$this->mysqli->escape_string($value):$value;
$query .= "$key='$value' ";
$i++;
if($i<count($where))
{
$query .= "AND ";
}
}
// check the max rowcount
$this->query($query,FALSE);
$result = $this->mysqli->use_result(); //<--this is the issue