I am wondering what PDO function that is equal to the db::getOne? I have this i need to change to PDO:
$count = db::getOne($query,$id,$showU['id']);
I am wondering what PDO function that is equal to the db::getOne? I have this i need to change to PDO:
$count = db::getOne($query,$id,$showU['id']);
$st = $pdodb->prepare($query);
$st->bindValue('id', $id);
$count = $st->fetchColumn();
This assumes you use named parameters which are always better than positional parameters IMO.
You really need to provide more info but im going to assume that id
and $showU['id']
are params to be bound to $query
and that getOne
retruns a single record. If these assumptions are correct you would do something like:
$query = "SELECT count(id) as nb_records FROM your_table_name WHERE id = :id AND uID = :uid";
$stmt = $pdo->prepare($query);
$stmt->execute(array(':id' => $id, ':uid' => $showU['id']);
$count = $stmt->fetchColumn();
You could of course chain these.
It's a user-defined function. One can use not only ready-made functions, but also create new ones. So, getOne is of this kind. It has nothing to do with PDO or other library. It's rather of your own library. But of course, it can be made by using PDO as well.
You can adopt this function to make a similar one which returns scalar value instead of array. But it seems you do not quite understand the meaning and the benefits (no offense - it's just matter of experience), so, nevermind. This function is not obligatory, it's just to make your code shorter and cleaner. Programming, in general, stands for eliminating repetitions. Most of local folks aren't programmers but rather copy/pasters. Most of them just don't care of code size or readability. Not quite bad, as long as their code works. So, you can go this way too.
The only purpose of this function is to do less work for you and make your code more readable. It doesn't affect any results. So, it's not obligatory.