Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 477
Eric Z Beard Avatar asked Aug 22 '08 13:08

Eric Z Beard


People also ask

How can we store data in PHP without database?

You can use the php function mail($to, $subject, $body) to send the email address to your personal email. The data will not be readable from your script, but for your use case this might be ok.

Can phpmyadmin handle big data?

PHPMyAdmin is able to handle unlimited amount of data when it comes to exporting a table to sql, csv or spreadsheets.

How do I debug a MySQL query?

Go to localhost/phpmyadmin, find the database, and then click on the SQL tab. Find the database before following this step. Now, paste the output in the text area and then click on the 'Go' button. STEP 4: Error, the query is debugged, Check the 'MySQL said' part to know the error with the query.


2 Answers

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.

like image 96
rix0rrr Avatar answered Oct 02 '22 22:10

rix0rrr


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.

like image 36
dragonmantank Avatar answered Oct 02 '22 20:10

dragonmantank