Location: PHPKode > projects > @1 File Store > libs/mysql.php
<?
//Êëàññ äëÿ ðàáîòû ñ áàçàìè MySQL
//Copyright (c) 2002 by NeWMaN Software
//E-mail: hide@address.com
//Description:
//Ðåàëèçàöèÿ îñíîâíûõ âîçìîæíîñòåé
//Âñå ìåòîäû âîçâðàùàþò â ñëó÷àå óñïåõà TRUE è FALSE â ñëó÷àå íåóäà÷è.

class MySQL
{
 var $connect=FALSE;
 var $errno=0;
 var $error="";
 var $res=FALSE;
 var $arr=FALSE;
 var $num=0;
 var $EOF=TRUE;
 var $SQL="";
//Êîíñòðóêòîð.
//Îòêðûâàåò ñîåäèíåíèå è âûáèðàåò áàçó 
 function MySQL($Base, $Host="localhost", $User="", $Pass="")
 {
 	$this->connect=mysql_connect($Host, $User, $Pass);
 	if($this->connect===FALSE)
 	{
 		$this->close(1);
 		return FALSE;
 	}
 	if(mysql_select_db($Base, $this->connect)===FALSE)
 	{
 		$this->close(2);
 		return FALSE;
 	}
 	return TRUE;
 }
//Âûáîð áàçû äàííûõ
 function select($Base)
 {
 	if($this->connect!==FALSE)
 	{
 		if(mysql_select_db($Base, $this->connect)===FALSE)
 		{
 			$this->close(2);
 			return FALSE;
 		}
 	}else
 	 {
 	 	$this->close(1);
 	 	return FALSE;
 	 }
 	 return TRUE;

 }
//Âûïîëíåíèå âûáîðêè
 function query($SQL)
 {
 	$this->SQL=$SQL;//Debug only
 	if($this->connect===FALSE)
 	{	
 		$this->close(1);
 		return FALSE;
 	}else
 	 {
         	if($this->res!==FALSE)
 			@mysql_free_result($this->res);
	 	$this->res=mysql_query($SQL, $this->connect);
	 	if($this->res==FALSE)
	 	{
	 		$this->close(3);
	 		return FALSE;
	 	}
	 	if(strncmp($SQL, "SELECT", 4)!=0)
	 		return TRUE;
	 	$this->num=mysql_num_rows($this->res);
	 	if($this->num===FALSE || $this->num==0)
	 	{
	 		$this->EOF=TRUE;
	 	}else
	 	 {
	          	$this->EOF=FALSE;
	         }
	 	$this->movenext();
	 	return TRUE;
	 }
 }
//Ïåðåõîä ê ñëåäóþùåé çàïèñè
 function movenext()
 {
 	$this->arr=mysql_fetch_array($this->res);
 	if($this->arr===FALSE)
 	{
 		$this->EOF=TRUE;
 		return FALSE;
 	}
 	return TRUE;
 } 
//Ïîëó÷àåò çíà÷åíèå ïîëÿ
 function field($Name)
 {
 	return StripSlashes($this->arr[$Name]);
 }
//Ïåðåâîäèò "êóðñîð" ðåçóëüòàòà â íóæíóþ ïîçèöèþ
 function reset($pos=0)
 {
 	if($this->num>0 && $this->res!==FALSE)
  		mysql_data_seek($res, $pos);
 }
//Çàâåðøåíèå ðàáîòû
 function close($error_level=0)
 {
 	if($error_level!=0)
 	{
 		$this->errno=$error_level;
 		$this->error=mysql_error($this->connect);
 	}
 	if($this->res!==FALSE)
 		@mysql_free_result($this->res);
	if($this->connect!==FALSE)
		@mysql_close($this->connect);
	return TRUE;
 }
}
?>
Return current item: @1 File Store