![]() |
Simple MySQL PDO Wrapper
I wrote this for a project I've been working on to help simplify database queries and keep the code clean. Also read that binding the parameters in your queries is great protection against injection hacks.
First, code examples INSERT/UPDATE PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
In this example, since you are having to write out the entire INSERT query, it would make more send to turn rename the insert() method query():
PHP Code:
|
Quote:
|
you can simplify your class by using Dependency Injection:
PHP Code:
another problem the class currently has (may have) is that it only supports string type data (the default data type for lazy bind) the other thing is that try … catch inside the constructor doesn’t make sense. firstly you shouldn’t print from a constructor. secondly, if your connection fails, the object is still created and will throw further errors if you try one of the methods ($this->pdo is not an object). use try … catch in your script where you can (programmatically) fix the problem (even if that means to skip the whole database section). |
| All times are GMT +1. The time now is 06:44 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.