Location: PHPKode > projects > Jarida > jarida_1.0/classes/class.db.cnx.sqlite.php
<?php
require_once("class.db.cnx.php");
require_once("class.db.result.sqlite.php");
/*

-------------------------------------------------------------------------

dbSqlite Class
      An sqlite wrapper class to be used to handle slite connectivity tasks.

-------------------------------------------------------------------------

Developer
      Name -- Haddad Said.
      Date -- 10-08-2005
      Version -- 1.2

-------------------------------------------------------------------------

Member Functions
      1.Constructor --  Obvious!
      2.initialize -- Here we will do all the database server connectivity.
      3.doQuery: -- Takes a mysql query and executes it.
      4.cleanup -- cleans up the garbarge (destructor type)

------------------------------------------------------------------------

*/

class dbCnxSqlite extends dbCnx
{
  
  //Variables to hold sqlite database connectivity credentials
  var $db_file;


  /*

-------------------------------------------------------------------------
Class Constructor
      
Parameters:
      file -- Location of the sqlite db file

Notes:
     Sets up the initial connectivity of the sqlite database.

Example Usage:
      $db = new dbSqlite("./test.db");

-------------------------------------------------------------------------

  */

  function dbCnxSqlite($file)
  {

    $this->db_error = '';
    $this->db_file = $file;

  }





  /*

-------------------------------------------------------------------------
Method initialize
      
Parameters:

Notes:
      Returns a false when an error occurs and a true when db connection
      and db selection is succesful. When an error occurs the error string
      is stored in $this->db_error. You can use $this->sendError() to
      display this error string.

Example Usage:
      if($db->initialize())
      {
        //Execute some code on succesful connection here.
      }
      else
      {
        //Send the error encountered.      
        echo $db->sendError();
      }

-------------------------------------------------------------------------

  */

  function initialize()
  {

    if(!($this->db_cnx = @sqlite_open($this->db_file)))
      {
	$this->db_error = "Could not open the file " . $this->db_file . " " . sqlite_error_string(sqlite_last_error());
	return false;
      }
    else
      {
	return true;
      }

  }




  /*

-------------------------------------------------------------------------

Method doQuery
      Takes an sql query as a parameter and executes the query

Parameters:
      query -- The query to be executed

Notes:
      If the query is successful the method returns true and the result
      resource is stored in $this->db_result. If the query is unsuccesful
      a false is returned

Example Usage
      $query = "Select user_id, user_name, user_email from tbluser";
      if($db->doQuery($query))
      {
        //Execute some code to handle the resultset.
      }
      else
      {
        //Send the error
        echo $db->sendError();
      }


-------------------------------------------------------------------------

  */

function doQuery($query)
  {
	if(!($this->db_result = @sqlite_query($this->db_cnx, $query)))
	  {
	    $this->db_error = "Could not perform the Query " . $query . " " .sqlite_error_string(sqlite_last_error($this->db_cnx));
	    return false;
	  }
	else
	  {
		return new dbResultSqlite($this, $this->db_result);
	  }
  }



  /*
-------------------------------------------------------------------------

Method cleanup
      This method cleans up after the object

Parameters:

Notes:
      Not really necessary, included for completeness.

Example Usage:
      //Lets do some cleaning
      $db->cleanup();
  
-------------------------------------------------------------------------
   */

  function cleanup()
  {
    sqlite_close($this->db_cnx);
    $this->db_cnx = '';
  }


}

?>
Return current item: Jarida