I recently tried using an old code I wrote for PHP 5.3 on a project that's running on a server that runs PHP 5.6. Though my code runs on my local machine (windows - PHP 5.3), it shows the error below when i try to use on my online host:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /home/lj7mxu21cx3y/public_html/crud/datamodel.php on line 54
Fatal error: Call to a member function execute() on boolean in /home/lj7mxu21cx3y/public_html/crud/datamodel.php on line 55
this is my code below:
function useRecord($mysqli,$query_string="",$type="",$vars=[]){
$query = $mysqli->prepare($query_string);
// create an empty array
$parameters = array();
// push the type string into the array by reference
$parameters[] = & $type;
// push the items from $vars array into the array by reference
for ($i = 0; $i < count($vars); $i++) {
$parameters[] = & $vars[$i];
}
// call mysqli_stmt::bind_param with the $parameters array, which contains [type, var1, var2, ...]
call_user_func_array(array($query, "bind_param"), $parameters);
$query->execute();
$result = null;
preg_match("/^[A-Z]+/", $query_string, $command);
switch ($command[0]) {
case "SELECT":
$result = $query->get_result();
break;
case "INSERT":
case "UPDATE":
case "DELETE":
$result = $query->affected_rows;
break;
}
$query->close();
return $result;
}
i am using the mysql native driver for php -- mysqlnd on my WebHost (Godaddy). EDIT:: Also, this function is used within a namespaced class
object(mysqli_stmt)#3 (10) { ["affected_rows"]=> int(0) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(1) ["field_count"]=> int(0) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) } object(mysqli_stmt)#3 (10) { ["affected_rows"]=> int(0) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(1) ["field_count"]=> int(4) ["errno"]=> int(0)