I am working on a small PHP website. I need a MySql database access class that is easy to configure and work with.
Does not need to be a full framework, I only need a max. few classes.
I am working on a small PHP website. I need a MySql database access class that is easy to configure and work with.
Does not need to be a full framework, I only need a max. few classes.
ADODb is pretty easy to work with and worth considering. Some illustrative samples:
//connect
$dsn = 'mysql://user:pwd@localhost/mydb';
$db = ADONewConnection($dsn);
//get a single value
$value=$db->GetOne("select foo from bar where x=?", array($x));
//get a row
$row=$db->GetRow("select * from bar where x=?", array($x));
//easy insert example
$record=array("id"=>1, "foo"=>"bar");
$db->AutoExecute("table", $record, "INSERT");
PDO works great for me, even tho it's not a fully blown library like PEAR::MDB2.
PDO is a compiled extension of PHP5, so there's a small performance benefit as well.
If you're happy with it being MySql specific, MySqli is the default choice.
You can try Zend_Db from Zend Framework. Later you may include mode components from ZF.
If you don't have really specific needs, I would recommend you take a look at PDO, which is bundled with PHP >= 5.1.
It's fully object-oriented, facilitates compatibility between DB engines ; and it's integration in PHP as a C extension makes it probably a bit faster than equivalents developped in PHP.
You could also take a look at the mysqli extension, which provides both a function-oriented and an object-oriented interface.
But I'd rather go to PDO, I think...
And, now that you are spending (investing ;-) ) some time looking for new stuff, you could take a look at prepared statements : they are supported by both mysqli and PDO, and are nice for (amongst other things) security reasons (no need to worry about escaping your data to prevent SQL injections)
If you had said you need a full ORM solution, I would have pointed you to Doctrine, which is really a great ORM framework ; but it's probably way too much for your needs...
I've used this once in a while, It's pretty good! (And has an awesome autoslash feature), it's easily customizable and pretty small, but it had everything I needed. You can probably relatively easy expand it to support caching or whatever you desire.
Good luck finding whatever suits you best. :)
Also digg's PDB, which is a simple PDO wrapper or something can be downloaded from http://code.google.com/p/digg/wiki/PDB