What's a good way to encapsulate data access with PHP/MySQL?

Most of my experience is on the MSFT stack, but I am now working on a side project, helping someone with a personal site with cheap hosting that is built on the LAMP stack. My options for installing extras are limited, so I'm wondering about how to write my data access code without embedding raw queries in the .php files.

I like to keep things simple, even with .NET. I generally write stored procedures for everything, and I have a helper class that wraps all calls to execute procedures and return data sets. I'm not looking for a full-blown ORM, but it might be the way to go and others who view this question might be looking for that.

Remember that I'm on a $7/month GoDaddy account, so I'm limited to what's already installed in their basic package.

Edit: Thanks rix0rr, Alan, Anders, dragon, I will check all of those out. I edited the question to be more open to ORM solutions, since they are so popular.

22.08.2008 13:04:29
6 ОТВЕТОВ

Take a look at the Zend Framework, specifically Zend_Db. It has a Database Abstraction layer that doesn't require anything other than the MySQLi extension to be installed and isn't a full-blown ORM model.

3
22.08.2008 13:08:46

Maybe Doctrine would do the job? It seems to be inspired by Hibernate.

3
22.08.2008 13:14:21

ActiveRecord seems to be the state of the art at the moment. I can't recommend any good PHP frameworks for that though. I tried Propel which, while nice, is not easy to set up (especially on a host that you can't install anything on).

Ultimately, I rolled my own ORM/ActiveRecord framework, which is not too much work and very instructive. I'm sure other people can recommend good PHP frameworks.

4
22.08.2008 13:15:32

rix0rrr hit on it a bit, in that many tools are a pain to set up. Of course, I have my own solution to this problem that has been working quite well for the past few years. It's a project called dbFacile

I also wrote a bit of a usage comparison of the tools I found a few years ago. It's incomplete, but might give you a good starting point.

You mentioned that you don't want to embed raw queries but you don't want ORM, so I'm a bit confused about the middle ground you're hoping to find. I also have an ORM project that aims to require minimal setup and great ease of use.

The only requirement for my projects is PHP5.

3
23.05.2017 12:33:27

I would try a framework. Zend Framework has been cited. Symfony seems interesting. It's based on ideas from Ruby on Rails.

1
22.08.2008 14:33:06

You could also take a look at Prado. http://www.pradosoft.com/ It uses Active Record and DAO. Also if you use .Net then some of the formatting and conventions are similar.

1
25.08.2008 20:40:54