I get this error when I try my code:
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in D:\AppServ\www\my\classes\db.class.php on line 23
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in D:\AppServ\www\my\classes\db.class.php on line 23
db.class.php file:
class DBclass{
private $servername;
private $username;
private $password;
private $dbname;
private $connect;
public function connectDB(){
$this->connect = mysqli_connect($this->servername,$this->username,$this->password,$this->dbname);
if(!$this->connect){
echo 'Error : Fail to connect to database !!' . mysqli_error($this->connect);
}
}
public function selectTBL($colum,$from,$where = '',$value = ''){
if($where == '' && $value == ''){
$query = 'SELECT '.$colum.'FROM '.$from;
}elseif($where != '' && $value != ''){
$query = 'SELECT '.$colum.'FROM '.$from.' WHERE '.$where. ' = '.$value;
}
mysqli_query($query,$this->connect) or die(mysqli_error($this->connect));
$row = mysqli_fetch_array($query);
return $row[$colum];
}
}
home.html file:
<?php $query = new DBclass; ?>
<html dir="rtl">
<head>
<title>title</title>
</head>
<body>
<?php $query->selectTBL('VALUE','SITE_CONFIGS','CONFIG','SITE_TITLE'); ?>
</body>
</html>