If course it would be nice to know what kind of a query is involved, but in any event the following code works:
<?php
error_reporting(E_ALL);
$id=5;
$code = 'GR';
$country='Greece';
$mysqli = new mysqli("localhost", "root", "", "exp");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " .
$mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
if (!($stmt = $mysqli->prepare("INSERT INTO countries VALUES (?,?,?)"))) {
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
//$stmt->bind_param('iss', $id, $code, $country);
$params = array('iss',$id,$code,$country);
$tmp = array();
foreach($params as $key => $value) $tmp[$key] = &$params[$key];
call_user_func_array( array($stmt, 'bind_param'), $tmp);
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
The code only works with my software when the $params array includes the letters specifying the type of data. Also the params themselves need to be references and not values. Note: I did borrow the code to turn values into references from this member of Stackoverflow.