What I'm trying to do is make a series of functions within classes that will make it easier to quickly carry out common tasks. In this instance I'm trying to create a Database class that has different functions eg connect, findRow.
I keep getting this error though when trying to call the findRow function: Fatal error: Call to a member function fetch_row() on a non-object
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;
}