Hi, I'm making a custom user management class that inherits from DBManager class. The problem I have so far is executing queries using mysqli prepared statements. DB connects fine but then prepare statement fails. I have mysqli object as an attribute that is shared in the class. I'm new with this mysqli (all the times I used normal mysql). Below is the constructor and insertusers method that fails.
Thanks
<?php
protected $dbLink;
protected $errorMsg = array();//Inherited by other functions
public function __construct() {
$this->dbLink = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno()) {
$this->addError(mysqli_connect_error());
}
}
public function insertUsers($arrayofValues) {
//for inserting users in the database
$sql = "INSERT INTO users(firstname, lastname, email, username, password) VALUES(?, ?, ?, ?, ?";
if( $stmt = $this->dbLink->prepare($sql)) {
$type = array("sssss");
$params = array_merge($type, $arrayofValues);
call_user_func_array(array($stmt, 'bind_param'), $this->refValues($params));
$stmt->execute();
if($stmt==-1) {
//query failed
$this->addError(mysqli_connect_error());
return false;
}else {
return true;
}
}
else{
$this->addError("Something went wrong before InsertUsers stmt could execute well");
}
}
?>