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

class icecube_mysql extends icecube_database
{
	private $_db_user;
	private $_db_pass;
	private $_db_name;
	private $_db_host;
	
	public function __construct($db_user, $db_pass, $db_host = "localhost")
	{
		//
		// check if mysql is installed
		//
		if(!function_exists("mysql_open"))
		{
			;
		}
		
		$this->_db_user = $db_user;
		$this->_db_pass = $db_pass;
		$this->_db_host = $db_host;
	}
	
	public function quick_connect($db_name)
	{
		$this->connect();
		$this->select($db_name);
	}
	
	public function connect()
	{
		$return = false;
		
		if(!$this->_db_user)
		{
			;
		}
		else if(!$this->_dbh = mysql_connect($this->_db_host, $this->_db_user, $this->_db_pass))
		{
			echo "cannt connect";
		}
		else
		{
			$return = true;
		}
		
		return true;
	}
	
	public function close()
	{
		mysql_close($this->_dbh);
	}
	
	public function select($db_name)
	{
		$return = false;
		
		if(!$db_name)
		{
			;
		}
		else if(!$this->_dbh)
		{
			;
		}
		else if(!mysql_select_db($db_name, $this->_dbh))
		{
			echo "opps";
		}
		else
		{
			$this->_db_name = $db_name;
			$return = true;
		}
		
		return $return;
	}
	
	public function escape($str)
	{
		return mysql_escape_string(stripslashes($str));
	}
	
	public function query($query)
	{
		$return = 0;
		$query = trim($query);
		
		$this->flush();
		
		$this->_last_query = $query;
		
		$this->_result = mysql_query($query, $this->_dbh);
		$this->_num_queries++;
		
		if(preg_match("/^(insert|update|delete|replace)\s+/i", $query))
		{
			$this->rows_affected = mysql_affected_rows();
			
			if(preg_match("/^(insert|replace)\s+/i", $query))
			{
				$this->insert_id = mysql_insert_id($this->_dbh);
			}
			
			$return = $this->rows_affected;
		}
		else
		{
			$i = 0;
			while($i < mysql_num_fields($this->_result))
			{
				$this->_column_info[$i] = mysql_fetch_field($this->_result);
				$i++;
			}
			
			$num_rows = 0;
			while($row = mysql_fetch_object($this->_result))
			{
				$this->_last_result[$num_rows] = $row;
				$num_rows++;
			}
			
			mysql_free_result($this->_result);
			
			$this->num_rows = $num_rows;
			$return = $this->num_rows;
		}
		
		return $return;
	}
}

?>
Return current item: Icecube