I have been struggling for days to figure how to follow OOP in the following procedure.
Here is my connection class which handles my connection to the database.
<?php
class Connection{
public $con = null;
public function __construct(){
return $this->con = new mysqli("127.0.0.1:3306", "root", "root", "tester");
}
}
?>
And here is my Helpers Class, this class contains all the common methods that will be used in my webapp like Insert data , delete and update.
<?php
class Helpers{
public $con = null;
public function __construct($connection){
$this->con = $connection;
}
public function register($name){
$con = $this->con;
$sql = "insert into name(Name)value($name);";
$con->query($sql);
}
}
?>
Now I call them like this in my register.php
<?php
require "Connection.php";
require "Helpers.php";
$connection = new Connection();
$Helpers = new Helpers($connection);
$Helpers->register("Keannu");
?>
But I am getting the following error:
Call to undefined method Connection::query().
What did I do wrong?