views:

65

answers:

3

I'm interested in learning more about design practices in PHP for Database Abstraction & Factory methods. For background, my site is a common-interest social networking community currently in beta mode.

Currently, I've started moving my old code for object retrieval to factory methods. However, I do feel like I'm limiting myself by keeping a lot of SQL table names and structure separated in each function/method.

Questions:

  1. Is there a reason to use PDO (or similar) if I dont anticipate switching databases?

  2. Can PDO interface with the MySqli prepared statements I currently use?

  3. Will it help me separate table names from each method? (If no, what other design patterns might I want to research?)

  4. Will it slow down my site once I have a significantly large member base?

+1  A: 

Nettuts recently had an article on some of the benefits to using PDO.

As for your question regarding abstraction, you might look into Object Relational Mapping (ORM) which lets you access database records the same way you would native php objects. Most of my experience has been with the Kohana framework, and I like how their ORM works, but many of the popular php frameworks should have good examples of database abstraction methods. I find that reading where someone else did it the "right" way helps me out.

Rookwood
+1  A: 

I would like to second Rookwood on looking at ORM. I have had good experciences with Doctrine. Building something yourself would be a waste of your time in moste cases.

jtietema
+1  A: 

I would recommend using PEAR or PDO.. why?

1) It's tested and used by tens of thousands of programmers. If you need another programmer to help you, there is a good chance they know PDO. There is basically zero chance they will know your API.

2) You don't think you will change databases.... BUT, what if a version change or something like that happens that forces you to migrate?

Zak