I am using Easyphp for development with default settings. All my code works fine with connection on local Easyphp db. But when I upload it on my webhosting which is using linux server - all functions with objects suddenly are returing OOP errors. This is exp. of normal function I normaly write:
function user_data($user_id){
global $db;
$data = array();
$user_id = (int)$user_id;
$func_num_args = func_num_args();
$func_get_args = func_get_args();
if($func_num_args > 1) {
unset($func_get_args[0]);
$fields = '`' . implode('`, `', $func_get_args) . '`';
$query = "SELECT $fields FROM users WHERE user_id = '$user_id'";
$result = $db->query($query);
$data = $result->fetch_assoc();
return $data;
$result->free();
$data->free();
}
}
Everything works fine on my local php server. After I upload it on webhosting with linux server I get " Call to a member function fetch_assoc() on a non-object error " on lines like :
$data = $result->fetch_assoc();
Can anybody tell me what I am writing wrong?
DB connection for easyphp:
$db = new mysqli("$DB_HOST","$DB_USER","$DB_PASSWORD","$DB_NAME");
DB connection for linux server:
$socket = "/tmp/mysql51.sock";
$db = new mysqli("$DB_HOST","$DB_USER","$DB_PASSWORD","$DB_NAME", 0, $socket);
Thank you
EDIT - SOLUTION
I found the reason for error. It is in writing variables in SQL query inside PHP code. Query should be like:
$query = "SELECT $fields FROM users WHERE user_id = '".$user_id."'";
Reason of error is still for me mistery. it can be platform or PHP versions.
Aucun commentaire:
Enregistrer un commentaire