I want to write a method for adding records to the database.
My method:
final public function newData($sql, $placeholder, $array) {
$stmt = $this->db->prepare($sql);
$stmt->bind_param($placeholder, implode(",", $array));
return $stmt->execute();
}
..................
// Code---Example
$sql = "INSERT INTO table (name, data) VALUES (?,?)";
$placeholder = "ss";
final public function newData($sql, $placeholder, [$array]) {
$stmt = $this->db->prepare($sql);
$stmt->bind_param($placeholder, implode(",", $array));
return $stmt->execute();
}
My problem is if I want to save several values with this method. I get a warning
Warning: mysqli_stmt:: bind_param (): Number of elements in type definition string doesn't match number of bind variables in ##
What am I doing wrong?