I need to convert this:
function user_data($user_id) {
$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) . '`';
$data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM users WHERE user_id = $user_id"));
return $data;
}
}
to this:
function user_data($user_id) {
$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 = $db->prepare("SELECT $fields FROM `admin` WHERE `id` = :user_id");
$query->bindParam(":user_id", $user_id);
$query->execute();
$data = $query->fetch(PDO::FETCH_ASSOC);
print_r ($data);
}
}
Problem is I cannot get the second bit to work. I keep getting this:
Fatal error: Call to a member function prepare() on a non-object in /home/ds4887/public_html/silverjet/v1.20/admin/core/functions/main.php on line 39
If you need any other information I will be more than glad to provide it. If not possible than can somebody please so me the correct method to do this. THe top works, the bottom needs to work.
Thanks in advance