Im getting this error and i dont know how to fix.
'Fatal error: Call to a member function query() on null in C:\xampp\htdocs\cms\lib\db.php on line 46'
Code:
class db {
public $mysqli;
function Connect() {
$server = 'localhost';
$dbusername = 'root';
$database = 'cms';
$dbpassword = 'lopaka';
$this->mysqli = new mysqli($server, $dbusername, $dbpassword, $database);
/* connectie bekijken */
if (mysqli_connect_errno()) {
printf("Connectie mislukt: %s
", mysqli_connect_error());
exit();
}
}
function GetGallery() {
$query = "SELECT * FROM menu";
$action = $this->mysqli->query($query);
while ($row = $action->fetch_assoc()) {
$gallery .= '<a href="'.$siteurl.''.$row['url'].'" title="'.$row['alt'].'" data-gallery="" ><img src="'.$siteurl.''.$row['url'].'" width="75px" height="75px"></a>';
}
return $gallery;
}
}
Thanks !!!
Edit - works now, but now i have some new errors:
Notice: Undefined index: url in C:\xampp\htdocs\cms\lib\db.php on line 42
Notice: Undefined index: alt in C:\xampp\htdocs\cms\lib\db.php on line 42
Notice: Undefined index: url in C:\xampp\htdocs\cms\lib\db.php on line 42
while ($row = mysqli_fetch_assoc($action)) {
$gallery .= '<a href="'.$siteurl.''.$row['url'].'" title="'.$row['alt'].'" data-gallery="" ><img src="'.$siteurl.''.$row['url'].'" width="75px" height="75px"></a>';
}
return $gallery;
You should add __construct() method to your class... add like this...
public function __construct()
{
$this->Connect();
}
Here the Connect() will initialized and then only mysqli query() method will work.