Answer the question
In order to leave comments, you need to log in
Why is PDO returning a string instead of a number?
There is a method:
public function getUser($user_id) {
$params = [
'user_id' => $user_id,
];
return $this->db->row('SELECT * FROM users WHERE id = :user_id', $params);
}
public function query($sql, $params = []) {
$stmt = $this->db->prepare($sql);
if (!empty($params)) {
foreach ($params as $key => $val) {
$stmt->bindValue(':'.$key, $val, (is_int($val) ? PDO::PARAM_INT : PDO::PARAM_STR));
}
}
$stmt->execute();
return $stmt;
}
public function row($sql, $params = []) {
$result = $this->query($sql, $params);
return $result->fetchAll(PDO::FETCH_ASSOC);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question