Location: PHPKode > projects > Icecube > icecube/databases/sqlite.php
<?php

class icecube_sqlite extends icecube_database
{
	private $_db_file;
	
	public function __construct($db_file)
	{
		//
		// check if sqlite is installed
		//
		if(!function_exists("sqlite_open"))
		{
			;
		}
		
		$this->_db_file = $db_file;
	}
	
	public function connect()
	{
		$return = false;
		
		if(!$this->_db_file)
		{
			;
		}
		else if(!$this->_dbh = sqlite_open($this->_db_file))
		{
			;
		}
		else
		{
			$return = true;
		}
		
		return $return;
	}
	
	public function quick_connect()
	{
		return $this->connect();
	}
	
	public function close()
	{
		sqlite_close($this->_dbh);
	}
	
	public function select($db_name)
	{
		$this->_db_file = $db_name;
		return $this->connect();
	}
	
	public function escape($str)
	{
		return sqlite_escape_string(stripslashes(preg_replace("/[\r\n]/", $str)));
	}
	
	public function query($query)
	{
		$return = 0;
		$query = str_replace("/[\n\r]/", "", trim($query));
		
		$this->flush();
		
		$this->_last_query = $query;
		
		$this->_result = sqlite_query($this->_dbh, $query);
		$this->_num_queries++;
		
		if(preg_match("/^(insert|delete|update|replace)\s+/i", $query))
		{
			$this->rows_affected = sqlite_changes($this->_dbh);
			
			if(preg_match("/^(insert|replace)\s+/i", $query))
			{
				$this->insert_id = sqlite_last_insert_rowid($this->_dbh);
			}
			
			$return = $this->rows_affected;
		}
		else
		{
			$i = 0;
			while($i < sqlite_num_fields($this->_result))
			{
				$this->_column_info[$i]->name = sqlite_field_name($this->_result, $i);
				$this->_column_info[$i]->type = null;
				$this->_column_info[$i]->max_length = null;
			}
			
			$num_rows = 0;
			while($row = sqlite_fetch_array($this->_result, SQLITE_ASSOC))
			{
				$obj = (object) $row;
				$this->_last_result[$num_rows] = $obj;
				$num_rows++;
			}
			
			$this->num_rows = $return = $num_rows;
		}
		
		return $return;
	}
}

?>
Return current item: Icecube