Skip to content
Advertisement

PHP mysqli_query() expects parameter 1 to be mysqli, null given in

I have 2 classes, controller and connector. They are used by delete.php. I got error saying

JavaScript

Does anyone know here did I make mistake? For me it looks like the link to the connection is badly passed to the controller class somewhere. Or the return doesnt work as I wanted. It all did work before I had to make it into classes…

class connector is here:

JavaScript

class controller is here

JavaScript

and delete.php:

JavaScript

Advertisement

Answer

Assuming your connection class is in ‘connection.php’,

JavaScript

Then, in your page, do this:

JavaScript

The reason is add the mysqli_connect and mysqli_close calls in the __construct and __destruct methods accordingly is because I am incredibly lazy and do not want to have to call a ->connect() method. And to be honest, my laziness has sometimes saved me a lot of work because I do not want to have to repeat myself over and over again (found out this is a coding philosophy called DRY – Don’t Repeat Yourself).

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement