So who here uses PDO?

Luke

Madly Diligent
Joined
Jun 11, 2010
Messages
5,396
Reaction score
2
FP$
14
So this weekend I am porting all of my social networks code from MySQL (I know tut tut) to PDO. PDO stands for PHP Data Objects and is something you will either find confusing or easy to use. I've found it fairly easy to use once you wrap your head around it, but the syntax isn't all too difficult!

Things look probably a little more different than what you MySQL/i developers use, I mean INSERT looks like this:

Code:
<?php
$stmt = $db->prepare("INSERT INTO table(field1,field2,field3,field4,field5) VALUES(:field1,:field2,:field3,:field4,:field5)");
$stmt->execute(array(':field1' => $field1, ':field2' => $field2, ':field3' => $field3, ':field4' => $field4, ':field5' => $field5));
$affected_rows = $stmt->rowCount();
?>

And it has named placeholders which is something I believe MySQLi doesn't offer (which is more useful than it sounds):

Code:
<?php
$stmt = $db->prepare("SELECT * FROM table WHERE id=:id AND name=:name");
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>

So who here actually uses PDO? MySQL obviously shouldn't be used for any new projects, but I've been using it and decided to weigh up the odds against MySQLi and PDO, and it seems as though PDO was the way to go.
 
I moved on to Codeigniter couple of years before and currently using Laravel for development. Laravel has Eloquent ORM to do all the dirty work for us. 😀

And Yeah! PDO should be the way to go for any app you develop from scratch. Also i would highly recommend using a framework with ORM or a standalone ORM for development, as it saves a lot of time.
 
Back
Top Bottom