Автор: ph4
Класс нарыл где-то на просторах Сети, вообщем-то штука удобная.
Code
<?
/*
Initilize the class:
$sldb = new sldb;
Connect to mysql & select database:
$sl->connect("host","user","password","database");
Run a query:
$query=$sl->query("Your Query");
Get a 1 row result:
$result=$sl->result("Your Query");
Get multiple row result:
$query=$sl->query("Your Query");
while($result=$sl->fetch($query)) {
//rows
}
$sl->free($query); //will free the $query
Get rows from query:
$query=$sl->query("Your Query");
$rows=$sl->rows($query);
Get rows without query first:
$rows=$sl->getrows("Your Query");
Get last insert id:
$last_id=$sl->last_id();
Disconnect from mysql:
$sl->disconnect();
*/
class sldb {
function connect($host,$user,$pass,$data,$persistency=False) {
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->data = $data;
$this->persistency = $persistency;
If($this->persistency) {
$this->link=@mysql_pconnect($this->host,$this->user,$this->pass);
} Else {
$this->link=@mysql_connect($this->host,$this->user,$this->pass);
}
If(($this->link) AND ($this->data)) {
If(@mysql_select_db($this->data,$this->link)) {
return True;
}
}
return False;
}
function fetch($query="") {
$query=@mysql_fetch_array($query);
return($query);
}
function query($query="",$sup="") {
If($sup) {
$query=@mysql_query($query,$this->link);
} Else {
$query=@mysql_query($query,$this->link) or die("<br /><br />".mysql_error()."<br /><br />");
}
return($query);
}
function rows($query="") {
$query=@mysql_num_rows($query);
return($query);
}
function free($query="") {
@mysql_free_result($query);
}
function result($query="",$sup="") {
$query=$this->query($query,$sup);
$result=$this->fetch($query);
$this->free($query);
return($result);
}
function getrows($querystring="") {
$query=$this->query($querystring);
$result=$this->rows($query);
$this->free($query);
return($result);
}
function disconnect() {
@mysql_close($this->link);
}
}
?>