次のエラーが表示されます。
Warning: Wrong parameter count for mysqli_stmt::bind_param()
パラメータを bind_param メソッドに間違った方法で割り当てているためだと思います。問題は、パラメーターの配列を bind_param に渡す方法です。
これは私の機能です:
function read($sql, $params)
{
$parameters = array();
$results = array();
// connect
$mysql = new mysqli('localhost', 'root', 'root', 'db') or die('There was a problem connecting to the database. Please try again later.');
// prepare
$stmt = $mysql->prepare($sql) or die('Error preparing the query');
// bind param ????????????
call_user_func_array(array($stmt, 'bind_param'), $params);
// execute
$stmt->execute();
// bind result
$meta = $stmt->result_metadata();
while ( $field = $meta->fetch_field() ) {
$parameters[] = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $parameters);
// fetch
while( $stmt->fetch() ) {
$x = array();
foreach( $row as $key => $val ) {
$x[$key] = $val;
}
$results[] = $x;
}
return $results;
}
これは私がそれを呼び出す方法です:
$params = array('i'=>$get_release, 'i'=>$status);
$result_set = read('SELECT release_id, release_group_id, status_id, name, subname, description, released_day, released_month, released_year, country_id, note, is_master_release, seo_url, meta_description, is_purchased FROM `release` WHERE release_id = ? AND status_id = ?', $params);