News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sitening.com:
Getting Real With Databases in PHP
June 01, 2006 @ 06:11:58

This new post on the Sitening.com blog (written up by Tyler Hall) today takes a look at PHP and databases (MySQL specifically in this case) and "getting real" with them.

many of the ideas behind Ruby on Rails are spot on. I particularly like how well it abstracts database queries into separate objects for each table. That's very cool and can save having to write a lot of repetitive code. But having to run a Rails script to generate new files is a little too cumbersome for me. Like I said, I prefer to keep things simple. Can we do the same thing with PHP? Using just one file?

Yes.

He proceeds to show a class that can perform operations similar to those styled in RoR - creating the object, applying proterties to it and performing the action (inserts/delete/etc). It's all made possible through the use of the __get and __set functions offered in PHP5. From there, it's just a simple matter of defining the functions for the actions.

To bring the point home, he also includes some examples of how to use this kind of functionality with a bit more than the previous example - selecting, updating, deleting, and inserting a new record (including the action function for each). Lastly, he gives an example of extending this base class, as mentioned in his first example (creating an object like "Animal" or "User" to abstract out the connections even more.

0 comments voice your opinion now!
getting real databases rubyonrails class __get __set getting real databases rubyonrails class __get __set


blog comments powered by Disqus

Similar Posts

PHP -GTK Community Site: A New Trio of Posts (phpISO, a PHP-GTK book, and Dev Inspector)

Community News: Big Nerd Ranch - PHP5 Bootcamp - 5-Day Intensive Training

DevShed: Using Yahoo Web Services to Perform Searches with an Object-Oriented Approach

Stubbles Blog: Do not trust the reflection API

Felix Geisendorfer's Blog: Assert the yummyness of your cake


Community Events

Don't see your event here?
Let us know!


voicesoftheelephpant security podcast example api video release series php7 interview laravel opinion extension introduction language version library laravel5 community framework

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework