I've taken over a Joomla project for a client that had some custom code written using the mysql_ commands running on PHP 5.4. I understand these were deprecated in PHP 7 and need help converting the file to run on PHP 7. I have changed the mysql_ commands to mysqli_ commands. I now have these errors displaying:
Notice: Constant _JEXEC already defined in /XXX/mod_admincustom.php on line 10
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in /XXXX/dbcontroller.php on line 21
Warning: mysqli_query() expects at least 2 parameters, 1 given in /XXXX/dbcontroller.php on line 25
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /XXXX/dbcontroller.php on line 26
Warning: mysqli_error() expects exactly 1 parameter, 0 given in /XXXX/dbcontroller.php on line 30
What do I need to change? Thanks :-)
class DBController {
private $host = "localhost";
private $user = "XXXX";
private $password = "XXXX";
private $database = "XXXX";
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($this->database,$conn);
}
function runQuery($query) {
$result = mysqli_query($query);
while($row=mysqli_fetch_assoc($result)) {
$resultset[] = $row;
}
if (!$result) {
die(mysqli_error());
}
if(!empty($resultset))
return $resultset;
}
function numRows($query) {
$result = mysqli_query($query);
$rowcount = mysqli_num_rows($result);
return $rowcount;
}
}