views:

1993

answers:

8

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.

+3  A: 

I think PEAR::MDB2 is what you are looking for.

soulmerge
+4  A: 

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");
Paul Dixon
I found ADODb to be the easiest one to set up.
Germstorm
Hi Mr. Dixon,But this library needs some good documentation. Do you know of any web resource where I can find some help with it. I tried to create a class for database related tasks using this library but couldn't do it well.
Gaurav Sharma
I found the documentation was OK (see http://phplens.com/lens/adodb/docs-adodb.htm )
Paul Dixon
+9  A: 

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.

Lior Cohen
+5  A: 

If you're happy with it being MySql specific, MySqli is the default choice.

therefromhere
+1  A: 

You can try Zend_Db from Zend Framework. Later you may include mode components from ZF.

Pawka
+3  A: 

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...

Pascal MARTIN
PDO does not facilitate compatibility between RDBMSes. It lacks constructs to hide the differences between things like how datetimes are handled differently across all RDBMSes. PDO is still a good choice for accessing any one RDBMS. But it is incomplete if cross-RDBMS support is necessary.
jmucchiello
+1  A: 

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. :)

Sirupsen
A: 

Also digg's PDB, which is a simple PDO wrapper or something can be downloaded from http://code.google.com/p/digg/wiki/PDB

Alfred