Administrators Nathan Posted June 23, 2012 Administrators Posted June 23, 2012 Interesting, so PDO is a library or something for PHP? Quote
Marc Posted June 23, 2012 Posted June 23, 2012 Why not just use PDO? http://us2.php.net/pdo PDO does pretty much what you're trying to do. It provides an object-oriented structure and a proper interface for prepared statements. It doesn't use mysql_* functions but it has equivalents. Here's a PDO script from start to finish: <?php new PDO('mysql:host=localhost;dbname=somedb','user','pass'); $sql = 'SELECT * FROM `sometable` WHERE `somecol`=?'; $sth = $dbh->prepare($sql); // prepared statements woo! $sth->execute(array('somevalue')); // ^ $out = $sth->fetchAll(); var_dump($out); ?> Dont see how that would do everything in the tutorial to be honest. Just a different way to connect and execute sql Quote
__Darknite Posted June 23, 2012 Author Posted June 23, 2012 Why not just use PDO? http://us2.php.net/pdo PDO does pretty much what you're trying to do. It provides an object-oriented structure and a proper interface for prepared statements. It doesn't use mysql_* functions but it has equivalents. Here's a PDO script from start to finish: <?php new PDO('mysql:host=localhost;dbname=somedb','user','pass'); $sql = 'SELECT * FROM `sometable` WHERE `somecol`=?'; $sth = $dbh->prepare($sql); // prepared statements woo! $sth->execute(array('somevalue')); // ^ $out = $sth->fetchAll(); var_dump($out); ?> You certainly can use PDO if you want But if you want a minimal and robust DAL then that's what the tutorial is for. Look libraries are fantastic things. However there seems to be an entire generation of "Software Engineers" that have become so dependent on frameworks and libraries that they are just "glue programming". As an example: One of our flagship internal enterprise company application has a virtual case board. It was originally created using off the shelf libraries. The performance was shockingly bad. I scrapped the entire module and re-wrote it by hand, using no libraries or frameworks. The result? The entire code was only a few hundred lines long versus the thousands of lines when you consider all the libraries and frameworks. I'm not suggesting not using libraries, you most certainly should. But at the same time, you should know how to roll things from scratch too. Marc 1 Quote
__Darknite Posted June 23, 2012 Author Posted June 23, 2012 Forgot to add, that in addition to having a vastly less code, it also ran much much faster. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.