-2

I am new to php so I am trying to figure this out whats wrong with this? i checked the code it says error in line 111 which is require_once("dbcontroller.php"); and dbcontroller i have posted

<?php
session_start();

require_once("dbcontroller.php");

<?php

class DBController {
    private $host = "localhost";
    private $user = "root";
    private $password = "";
    private $database = "tblproduct";
    private $conn;
    
    function __construct() {
        $this->conn = $this->connectDB();
    }
    
    function connectDB() {
        $conn = mysqli_connect($this->host,$this->user,$this->password,$this->database);
        return $conn;
    }
    
    function runQuery($query) {
        $result = mysqli_query($this->conn,$query);
        while($row=mysqli_fetch_assoc($result)) {
            $resultset[] = $row;
        }       
        if(!empty($resultset))
            return $resultset;
    }
    
    function numRows($query) {
        $result  = mysqli_query($this->conn,$query);
        $rowcount = mysqli_num_rows($result);
        return $rowcount;   
    }
}
?>
  • Are you sure it's the correct line? Because it shouldn't throw this error – Alon Eitan May 24 '22 at 11:35
  • Side note; why not cache your query result after using runQuery into a private variable (e.g. `private $lastResult;`) and call mysqli_num_rows on that rather than run a query twice? Probs not in your case, but running the same query twice on 10m+ rows of data seems silly :) – Can O' Spam May 24 '22 at 11:36
  • yes it keeps giving me this error – Ahmed Agha May 24 '22 at 11:38
  • 1
    You may have some invisible characters messing up the syntax. Delete everything from `class DBController` up, and retype it. – aynber May 24 '22 at 11:39
  • i checked on https://phpcodechecker.com there is nothing wrong – Ahmed Agha May 24 '22 at 11:40

0 Answers0