Can anyone help me solve this? I having this line code with error of
PHP Fatal error: Call to a member function fetch_assoc() on string in
C:\inetpub\wwwroot\dbcontroller.php on line 26
Line 26 is this line of code: $result = $query->fetch_assoc();
class DBController {
private $host = "localhost";
private $user = "root";
private $password = " ";
private $database = "test";
function __construct() {
$conn = $this->connectDB();
if(!empty($conn)) {
$this->selectDB($conn);
}
}
function connectDB() {
$conn = mysqli_connect($this->host,$this->user,$this->password);
return $conn;
}
function selectDB($conn) {
mysqli_select_db($conn,$this->database);
}
function runQuery($query) {
$result = $query->fetch_assoc();
// $result = mysqli_query($query);
while($row=mysqli_fetch_assoc($result)) {
$resultset[] = $row;
}
if(!empty($resultset))
return $resultset;
}
function numRows($query) {
$result = mysqli_query($query);
$rowcount = mysqli_num_rows($result);
return $rowcount;
}
}
?>
No comments:
Post a Comment