我要做的是在类中创建一系列函数,以便更快地执行常见任务。在这个例子中,我正在尝试创建一个具有不同功能的Database类,例如connect,findRow。
我在尝试调用findRow函数时仍然遇到此错误: 致命错误:在非对象上调用成员函数fetch_row()
class Database {
public $host = "";
public $username = "";
public $password = "";
public $database = "";
public $db_connect;
/**
* Connect to database
*/
function connect($host, $username, $password) {
$connection = new mysqli($host,$username,$password);
if($connection->connect_errno > 0){
die('Unable to connect to database [' . $connection->connect_error . ']');
} else {
$this->db_connect = $connection;
return true;
}
}
/**
* Pulls an entire row from search by Table > Column > Value
*/
function findRow($table,$column,$value) {
echo $query = "SELECT * FROM ".$table." WHERE ".$column."='".$value."'";
$result = $this->db_connect->query($query);
echo $result;
$row = $result->fetch_row();
return $row;
}