Location: PHPKode > scripts > Encaps Gallery > encaps-2.3.22s/core/db_sql.class.php
<?php
class DB_sql{
	
	function DB_sql($host,$user,$pass,$db,$debug=false)
	{
		$this->host = $host;
		$this->user = $user;
		$this->password = $pass;
		$this->db = $db;
		$this->debug = $debug;
		$this->result = true;
		$link = mysql_connect($this->host,$this->user,$this->password) or $this->result = "Error on mysql_connect()";
		if($this->result === true)
			mysql_select_db("$this->db") or $this->result = "Error on mysql_select_db()";
		mysql_query("SET NAMES UTF8");
	}

	function query($sql)
	{
		//0-silent
		//1-show errors
		//2-show all
		if(!$this->debug)
			$result=mysql_query($sql);
		else
		{
			if($this->debug == 2)
				echo "<br/>[".$sql."]";
			$result=mysql_query($sql) 
				or print("<br/><b>SQL error:</b>[$sql]". mysql_error());
		}
		
		if(!preg_match("#^\s*SELECT #i",$sql)) 
			return $result;

		$returned = array();
		if($result)
		{
			while($line = mysql_fetch_array($result/*, MYSQL_ASSOC*/))
			{
				$returned[] = $line;
			}
			mysql_free_result($result);
		}

		if(preg_match("#LIMIT +1[^\d]*$#is",$sql))
			return $returned[0];

		return $returned;
	}

}
?>
Return current item: Encaps Gallery