so i'm trying make 1 class (for mysqli operations) reusable other classes (which use different tables , parameters) possible. fragment main class:
class sql { private $sql; public function __construct() { $this->sql = new mysqli(db_host, db_user, db_password, db_database); if ($this->sql->connect_errno > 0) { die('unable connect database: ' .$this->sql->connect_error); } elseif (!$this->sql->set_charset("utf8")) { printf('error loading character set utf8: ' .$this->sql->error); } } public function newentry($table, $entrystring, $valuestring, $typestring, $datastring) { $statement = $this->sql->prepare("insert $table($entrystring) values ($valuestring)"); $statement->bind_param($typestring, $datastring); $statement->execute(); $statement->close(); $this->sql->close(); } }
and here other class, in i'm trying pass variables main function newentry():
class user extends sql { protected $table = 'foo'; public function newuser($name, $surname) { $entrystring = 'name, surname'; $valuestring = '?, ?'; $typestring = 'ss'; $datastring = '$name, $surname'; parent::newentry($this->table, $entrystring, $valuestring, $typestring, $datastring); } }
so when i'm trying execute this, "warning: mysqli_stmt::bind_param(): number of elements in type definition string doesn't match number of bind variables in..". understand it's because $datastring acts single entry: "john, doe". there way make act numerous separate params instead of string?
Comments
Post a Comment