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:
And it has named placeholders which is something I believe MySQLi doesn't offer (which is more useful than it sounds):
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.
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.







