Reputation: 815
I have this script trying to put array into mysqli_stmt_bind_param, I googled around and found this solution, however, the code doesn't seems to be working properly. I received no results from database and a warning.
Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object
Here is my code:-
$sql_param = array();
$params = array();
$query = "SELECT campname,url,views,leads,subs,country,affid FROM camp WHERE";
if (isset($_POST['fromdatetime']) && isset($_POST['todatetime'])) {
$datefrom = $_POST['fromdatetime'].":00";
$dateto = $_POST['todatetime'].":59";
$sql_param[] = $datefrom;
$sql_param[] = $dateto;
$bindparam = "ss";
$query .= "datevisit between (?) AND (?)";
}
if (isset($_POST['affidcode'])) {
$affidcode = $_POST['affidcode'];
$sql_param[] = $affidcode;
$bindparam .= "s";
$query .= " AND affid = (?)";
}
$sql_param_count = count($sql_param);
$params[] = &$bindparam;
for($i = 0; $i < $sql_param_count; $i++) {
$params[] = &$sql_param[$i];
}
/* create a prepared statement */
$stmt = mysqli_prepare($mysqli, $query);
call_user_func_array(array($stmt, 'mysqli_stmt_bind_param'), $params);
/* execute query */
$status = mysqli_stmt_execute($stmt);
Upvotes: 4
Views: 7735
Reputation: 1201
Ensure that $stmt
is valid mysqli_stmt
object (not false
) after this block:
/* create a prepared statement */
$stmt = mysqli_prepare($mysqli, $query);
Then try this:
array_unshift($params, $stmt);
call_user_func_array('mysqli_stmt_bind_param', $params);
Upvotes: 1