//clasa dbconnect
class dbconnect {
var $nrElemPag=20; //nb of elements displayed in main query
var $nbPageDisp=15; // nb of pages displaye at the bottom
function dbconnect($host,$user,$pass,$db) {
$this->connect($host,$user,$pass,$db);
}
function connect($host,$user,$pass,$db) {
$this->conn=mysql_connect($host,$user,$pass) or die("eroare la conectarea catre baza de date: ".mysql_error());
if ($this) $this->select($db);
else
return false;
}
function select($db){
$this->bd=mysql_select_db($db) or die("eroare la selectarea bazei de date: ".mysql_error());
if ($this) return true;
else
return false;
}
function query($string,$debug=0){
if ($debug==1) echo "\n
".$string."
"; //for debug mode only
$search=mysql_query($string) or die("eroare in query: ".mysql_error()."
".$string);
$tmp = array();
while ($linie=mysql_fetch_array($search)) array_push($tmp,$linie);
mysql_free_result($search);
return $tmp;
}
function run($string,$debug=0){
if ($debug==1) echo "\n
".$string."
"; //for debug mode only
$search=mysql_query($string) or die("eroare in query: ".mysql_error()."
".$string);
if ($search) return true;
else
return false;
}
function counter($string,$debug=0){
$this->buffer.='explain '.$string.';'."
";
if ($debug==1) echo "\n
".$string."
"; //for debug mode only
$search=mysql_query($string) or die("Eroare in query.Contact administrator. ".($debug==1?$_SERVER['PHP_SELF'].' | '.mysql_error()."
".$string:''));
$num=mysql_fetch_array($search);
return $num[0];
}
function last_id(){
return mysql_insert_id();
}
function affected(){
return mysql_affected_rows();
}
function protect($param,$html=''){
if ($html=='') $html=array(); //compatibilitate cu scripturile vechi
if (is_array($param)){
foreach ($param as $key=>$val){
if (!is_array($val)){
if (!in_array($key,$html))
$param[$key]=$this->protect($val,$html);
else
$param[$key]=$this->protect(strip_tags($val),$html);
}
else
$param[$key]=$this->protect($val,$html);
}
}
else{
//generalizare pt config server
$param=get_magic_quotes_gpc?stripslashes($param):$param;
//se encodeaza entitatile in HTML
$param=htmlspecialchars($param,ENT_QUOTES,'UTF-8');
//protectie scriere in baza de date;
$param=mysql_real_escape_string($param);
}
return $param;
}
function unprotect($param,$html=''){
if ($html=='') $html=array(); //compatibilitate cu scripturile vechi
if (is_array($param)){
foreach ($param as $key=>$val)
$param[$key]=$this->unprotect($val,$html);
}
else{
$param=stripslashes($param);
$param=htmlspecialchars_decode($param);
}
return $param;
}
function stats(){
return mysql_stat();
}
function pre($tmp){
echo '
'; print_r($tmp); echo ''; } function preselect($v1,$v2,$tip=0){ $text=array(' selected',' checked'); if ($v1==$v2) return $text[$tip]; } } //$obj=new dbconnect('localhost','root','amzdev','implozia'); $obj=new dbconnect('localhost','globalte_global','abcd1234','globalte_global'); $obj->run('SET NAMES utf8'); $obj->run('SET CHARACTER SET utf8'); $obj->run("SET COLLATION_CONNECTION='utf8_general_ci'"); class paginare{ var $start=0; var $limit=0; var $pages=0; var $search=array('/\t/','/\r\n/','/select .+ from/i','/order.+/i'); var $repl=array(' ',' ','select count(*) from',''); var $get; var $file_; var $afisare; function paginare($string,$file,$afisare){ global $obj; $this->file_=$file; $this->afisare=$afisare; foreach ($_GET as $key=>$val) if ($key<>'l') $this->get.=$key.'='.$val.'&'; //se calculeaza nr pag preg_match('/limit ([0-9]+),([0-9]+)/i',$string,$limit); $this->start=$limit[1]; $this->limit=$limit[2]; $string=preg_replace($this->search,$this->repl,$string); $allRes=$obj->counter($string,0); if ($this->limit>0){ $this->pages=ceil($allRes/$this->limit); $this->afisare(); } } function afisare(){ switch($this->afisare){ case "1": $this->tip1(); break; //admin case "2": $this->tip2(); break; //front1 } } function tip1(){ for ($i=0; $i<($this->pages<$this->limit?$this->pages:$this->limit); $i++) echo '[ '.($i+1).' ] '; } function tip2(){ $pag=floor($_GET['l']/$this->limit); echo '