Reputation:
Okay so i have been using PDO for all my practice projects where i also made a PDO class. Now what i want to do is make a MYSQLI version of the class but i am having trouble understanding how to use MYSQLI Prepared statements in this function:
public function query($sql, $params = array())
{
$this->_error = false;
if ($this->_query = $this->_mysqli->prepare($sql)) {
$x = 1;
if (count($params)) {
foreach ($params as $param) {
$this->_query->bindValue($x, $param);
$x++;
}
}
if ($this->_query->execute()) {
$this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count = $this->_query->rowCount();
} else {
$this->_error = true;
}
}
return $this;
}
As you can see this has only been partly converted i am having trouble understanding where to do from here. Thanks for your suggestions.
Upvotes: 0
Views: 108
Reputation: 1674
http://php.net/manual/en/mysqli-stmt.bind-param.php
mysqli uses bind_param($str, $param1, $param2, ...)
where $str is a concatenation of types (one char each, 'i', 'd', 's', or 'b'. see the manual link above)
i.e. bind_param('sss', $string1, $string2, $string3);
if all your params are the same type you could use str_repeat based on count($params) to generate this. else you'll have to do something a bit more complex to get the types.
Upvotes: 1