Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make PDO simpler

While I converted myself (finally!) from mysql_connect() to PDO::etc and all the other mysql functions, to adopt a better, DB abstraction coding style to my websites, I couldn't help noting how object oriented, error exception handling and prepared statements based this stuff is. I'm OK with all this, but I'm sure the beginner next to me only gets as far as the simplicity of copy-and-paste.

Are there any libraries/scripts/user contributions to make the DBO calls simpler, such as removing exception handling and object orientate, or at least n00b friendly?

I have made my own library with PDO, but I'm not sure what there is already out there?

like image 938
Florian Mertens Avatar asked Oct 05 '22 07:10

Florian Mertens


1 Answers

You can use a framework that uses an ORM, like Laravel: http://laravel.com/docs/database/eloquent

But then you are not writing your own SQL-queries (or its not recommended), else you can just use MySQLi: http://se2.php.net/mysqli_query but neither of them removes any objective view I think. But both may be easier to understand for a new programmer.

I recommend you to go for a framework on at least your future projects.

Here is some examples of them all:

  • http://laravel.com/docs/database/eloquent (Laravel)
  • http://ellislab.com/codeigniter/user-guide/database/active_record.html (CodeIgniter)
  • http://book.cakephp.org/2.0/en/models/retrieving-your-data.html (CakePHP)
  • http://li3.me/docs/manual/quickstart (Lithium, for alternative database MongoDB)
like image 97
Ms01 Avatar answered Oct 10 '22 10:10

Ms01