Update 2010: My website now has a lot of.. venerable content on it. I’m leaving this in for posterity, but I wouldn’t use it if I were you…

This is a simple class that I created whilst learning PHP for my MSc project to provider an adaptor to encapsulate MySQL database access. Rather than providing a MySQL resource which results in bloat if you merely want the dataset, it provides the query result as a two-dimensional array. It trades direct recordset access (and efficency when traversing large results) for easier data manipulation, as well as the usual benefits about hiding complexity such as conection details and other complexity.

I’m making further use of this class in my subsequent projects.

Download version 1.1 (10 November 2004)

Example usage:

require ('rh_dao.class.php');
		  $rh = new RH_DAO;
		  $data = $rh->select("select * from table_foo where field_foo= 'bar'");
		  echo $data[0]['id']; //id of first record
		  $update[0]["name"] = "joe";
  $update[0]["initials"] = "j";
  $update[1]["name"] = "fred";
  $update[1]["initials"] = "f";
  $rh->insert("table_foo", $update); //insert data
  $rh->delete("dummy_table", 1,"id")); //delete where id=1

blog comments powered by Disqus

Switch to our mobile site