I am just learning classes , i am trying to add data using mysql bind params but unable to do so , seems some silly mistake , please help me with is , i want to do it with oops way , else i can do it.
Error : Parse error: syntax error, unexpected '$mysqli' (T_VARIABLE), expecting function (T_FUNCTION) in customer.php on line 4
Index.php
$adduser= new Userclass();
echo $adduser->addcutomer();
Db class.php
class db extends mysqli {
private static $instance = null;
private $user = "root";
private $pass = "xxx";
private $dbName = "xxx";
private $dbHost = "localhost";
public static function getInstance() {
if (!self::$instance instanceof self) {
self::$instance = new self;
}
return self::$instance;
}
public function __clone() {
trigger_error('Clone is not allowed.', E_USER_ERROR);
}
public function __wakeup() {
trigger_error('Deserializing is not allowed.', E_USER_ERROR);
}
private function __construct() {
parent::__construct($this->dbHost, $this->user, $this->pass, $this->dbName);
if (mysqli_connect_error()) {
exit('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
parent::set_charset('utf-8');
}
public function dbquery($query)
{
if($this->query($query))
{
return true;
}
}
}
Customer Class
class Userclass extends db{
$mysqli=db::getInstance();
public function addcutomer(){
$query = $mysqli->prepare("INSERT INTO `user` (`firstname`,`lastname`) VALUES (?, ?)");
$col1 = 'abc';
$col2 = 'def';
$query->bind_param('ss', $col1, $col2);
$query->execute();
$query->close();
return true;
}