<p>I have inherited an old crusty <code>PHP application</code>, and I'd like to refactor it into something a little nicer to deal with, but in a gradual manner. In perl's CPAN, there is a series of classes around Class::DBI that allow you to use database rows as the basis for objects in your code, with the library generating <code>accessor methods</code> etc as appropriate, but also allowing you to add additional methods.</p>

<p>Does anyone know of something like this for PHP? Especially something that doesn't require wholesale adoption of a "framework"... bonus points if it works in PHP4 too, but to be honest, I'd love to have another reason to ditch that. :-)</p>

[{'answer_id': 8310, 'author': 'GaryF', 'author_id': 1035, 'author_profile': 'https://Stackoverflow.com/users/1035', 'pm_score': 3, 'selected': True, 'text': '<p>It\'s now defunct but <a href="http://phpdbi.sourceforge.net/web/" rel="nofollow noreferrer">phpdbi</a> is possibly worth a look. If you\'re willing to let go of some of your caveats (the framework one), I\'ve found that <a href="http://www.phpdoctrine.org/" rel="nofollow noreferrer">Doctrine</a> is a pretty neat way of accessing DBs in PHP. Worth investigating anyway.</p>\n'}, {'answer_id': 8338, 'author': 'ggasp', 'author_id': 527, 'author_profile': 'https://Stackoverflow.com/users/527', 'pm_score': 0, 'selected': False, 'text': '<p>The right thing to is to access the database via an abstraction layer in a way such if you change your RDBMS or how you implemented that access, you only have to modify this layer while all the rest of your application remains untouched. </p>\n\n<p>To do this, to free your application from knowing how to deal with the database, your abstraction layer for DB access must be implemented by a framework such as <a href="http://adodb.sourceforge.net/" rel="nofollow noreferrer">ADODB</a>. </p>\n\n<p>All the files related to this layer must be located in a sub directory:</p>\n\n<ul>\n<li>/ado</li>\n</ul>\n\n<p>In this directories you\'ll put all of your .php.inc files which contains general methods to access the database.</p>\n'}, {'answer_id': 9274, 'author': 'Pat', 'author_id': 238, 'author_profile': 'https://Stackoverflow.com/users/238', 'pm_score': 0, 'selected': False, 'text': '<p>How about <a href="http://pear.php.net/package/MDB2" rel="nofollow noreferrer">MDB2</a> from pear?</p>\n\n<blockquote>\n  <p>It provides a common API for all\n  supported RDBMS. The main difference\n  to most other DB abstraction packages\n  is that MDB2 goes much further to\n  ensure portability.</p>\n</blockquote>\n\n<p>Btw: @GaryF what are those strange title attributes your links have ? Did you add them or are they added by SO ?</p>\n'}, {'answer_id': 32922, 'author': 'Jack M.', 'author_id': 3421, 'author_profile': 'https://Stackoverflow.com/users/3421', 'pm_score': 1, 'selected': False, 'text': '<p>Class::DBI is an <a href="http://en.wikipedia.org/wiki/Object-relational_mapping" rel="nofollow noreferrer">ORM (Object Relational Mapper)</a> for perl.  Searching for "PHP ORM" on google gives some good results, including <a href="http://www.doctrine-project.org/" rel="nofollow noreferrer">Doctrin</a>, which I\'ve had good luck with.  I\'d start there and work your way up.</p>\n'}, {'answer_id': 52593, 'author': 'Alan Szlosek', 'author_id': 3756, 'author_profile': 'https://Stackoverflow.com/users/3756', 'pm_score': 1, 'selected': False, 'text': '<p>I\'m trying to get more feedback on my own projects, so I\'ll suggest my take on ORM:  <a href="http://greaterscope.net/projects/ORMer" rel="nofollow noreferrer">ORMer</a></p>\n\n<p>Usage examples are <a href="http://greaterscope.net/projects/ORMer/examples" rel="nofollow noreferrer">here</a></p>\n\n<p>You can phase it in, it doesn\'t require you to adopt MVC, and it requires very little setup.</p>\n'}]
['https://Stackoverflow.com/questions/8276', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/923/']