phptutorials.cjb.net - Free PHP Tutorials and Advice
 

PHP Classes Tutorial 1 - Database Abstraction and Classes Tutorial - Page 4 of 7

Basic Methods

Now we are going to write a few basic methods that we will need. The constructor provides us with a database connection, but we will need a method to select a database, execute a query and retrieve information.  For this we will use the following functions:


	function selectDB( $db_name )
	{
		mysql_select_db( $db_name, $this->connect_id );
	}

	function query( $query )
	{
		return mysql_query( $query, $this->connect_id );
	}

	function fetch_Object( $query )
	{
		return mysql_fetch_object( $query );
	}

	function fetch_Array( $query )
	{
		return mysql_fetch_array( $query );
	}

	function fetch_Row( $query )
	{
		return mysql_fetch_row( $query );
	}

Links open corresponding PHP manual page in new window

These methods will give us basic functionality for our dal, example usage will be given later, but next we will look at some potentially useful advanced methods.