Napisalem abstrakycjna klase do obslugi bazy mysql
Co o niej sadzicie?
Chce na niej bazowac w duzym projekcie i nie chcialbym wtopic
Jak robic cachowanie? Nie mam pomyslu...
<?php
class db{
public $_link; // connection id
public $_database; // selected db
public $_query; // current query
public $_resource; // data resource
public $_data; // data
public $_rows; // number of processed rows
public $_queries=0; // number of queris
public $_lastId; // last primary key
public function connect($host, $login, $pass, $_database){
$this -> _link = $_link;
else{
$this -> error();
return false;
}
$this -> _database = $_database;
else{
$this -> error();
return false;
}
return true;
}
public function query($_query){
if(!$this -> _link || !$this -> _database){
$this -> error("can not do _query - no _database selected");
return false;
}
$this -> _query = $_query;
if($this -> _resource)
$this -> _resource = $_resource;
else{
$this -> error();
return false;
}
$this -> _queries++;
return $this -> _resource;
}
public function getData(){
if(!$this -> _link || !$this -> _database || !$this -> _resource){
$this -> error("can not get data from resource - no database selected or there is no data recosurce");
return false;
}
$this -> _data[]=$_data;
return $this -> _data;
else
$this -> error();
}
public function getOnce(){
if(!$this -> _link || !$this -> _database || !$this -> _resource){
$this -> error("can not get data from resource - no database selected or there is no data recosurce");
return false;
}
$this -> _data[0]=$_data;
return true;
}
else
return false;
}
public function numRows(){
if(!$this -> _link || !$this -> _database || !$this -> _resource){
$this -> error("can not get data from _resource because no _database selected or there is n
o data recosurce");
return false;
}
$this -> _rows = $_rows;
return $_rows;
}
if($this -> _resource)
unset($this -> _resource
); $this -> _queries=0;
return true;
}
private function error($error=false){
if($error)
echo "<p style=\"font-weight:bold;color:red;\">".$error."</p>"; if($this -> _query!="")
echo "<p style=\"font-weight:bold;color:red\">".$this -> _query
."</p>"; }
public function __destruct(){
if($this -> _link && $this -> _db){
$this -> _error();
return false;
}
else
return true;
}
else
return true;
}
}
?>
Ten post edytował Beynar 11.12.2007, 22:59:41