I have 2 classes, controller and connector. They are used by delete.php. I got error saying
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\pracownia\kontroler.php on line 38
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\pracownia\kontroler.php on line 44
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:
<?php
class connector {
private $db_handle="";
private $user_name;
private $password;
private $database;
public static $server = "127.0.0.1";
function __construct($user_name="", $password="", $database="")
{
$this->user_name = $user_name;
$this->password = $password;
$this->database = $database;
}
function connect()
{
$this->db_handle = mysqli_connect(self::$server,$this->user_name,$this->password);
if(!$this->db_handle)
{
die('Could not connect: ' . mysqli_error());
}
mysqli_select_db($this->db_handle,$this->database);
return $this->db_handle;
}
function disconnect()
{
mysqli_close($this->db_handle);
}
}
?>
class controller is here
<?php
class kontroler {
private $db_handle;
private $name;
private $surname;
private $password;
private $email;
private $id;
private $sql;
function _construct($db_handle="")
{
$this->db_handle = $db_handle;
}
function delete_user($id="")
{
//$this->sql = "DELETE FROM UZYTKOWNICY WHERE ID_UZ=$id";
if(mysqli_query($this->db_handle,"DELETE FROM UZYTKOWNICY WHERE ID_UZ=$id"))
{
echo "Record deleted successfully";
}
else
{
die ('Error deleting record: ' . mysqli_error($this->db_handle));
}
}
}
?>
and delete.php:
<?php
global $db_handle;
include 'kontroler.php';
include 'connector.php';
//require_once('kontroler.php');
//require_once('connector.php');
$connection = new connector("root","","proj");
$db_handle = $connection->connect();
$kontrol = new kontroler($db_handle);
$kontrol->delete_user('$_POST[id]');
$connection->disconnect();
?>