I’ve been staring at this for a long time now and have tried everything I can think of. I’m working on a class to handle all data connections using prepared connections. The query function works perfectly. However, I wanted to add functionality for a database insert. In order to do this I created a second functino called insert (because the first function throws an error during an insert because there are no return results).
However, I can not get the insert function to work for the life of me. It is very simple and I’ve broken it down into even simpler form but it continues to not work In the insert function I’ve temporarily overridden the parameters with a static sql query (that I have confirmed works). Any suggestions on why this is not working? Anything to do with multiple instances of mysqli?
I’ve tried a couple debugging techniques but have been unable to find a way to print out any error messages that might occur in the process.
<?php
class Database {
protected $mysqli;
public function __construct() {
include ('conf/db.conf');
$this->mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
$this->mysqli->autocommit(false);
}
public function query($sql, $type, $values) {
$items = array();
$mysqli = $this->mysqli;
$this->clean($values);
if($stmt = $mysqli->prepare($sql)){
call_user_func_array('mysqli_stmt_bind_param', array_merge(array($stmt, $type), $values));
$stmt->execute();
$meta = $stmt->result_metadata();
while($field = $meta->fetch_field()){
$params[] = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
while($stmt->fetch()){
foreach($row as $key => $val){
$c[$key] = $val;
}
$items[] = $c;
}
$stmt->close();
}
return $items;
}
public function insert($sql, $type, $values) {
$mysqli = $this->mysqli;
$this->clean($values);
$sql = "INSERT INTO Tickets (submitDate, tDesc, pid, cid) VALUES('2010-03-10', 'test', 15, 10)";
if($stmt = $mysqli->prepare($sql)){
//call_user_func_array('mysqli_stmt_bind_param', array_merge(array($stmt, $type), $values));
$stmt->execute();
$stmt->close();
}
}
}