<?php
class DB
{
var $cashe_dir = ''; //katalog, w którym składowane są cashe z danego pliku
var $cashe_file = 'cashe'; //plik cashe
var $conn;
var $db;
var $result;
var $rows;
//funckcja sprawdzająca czy plik cashe isnieje
function cashe_exists($var)
{
{
return(true);
}
else
{
return(false);
}
}
//funckja otwierająca połączenie
function connect($host, $db_user, $db_pass, $db_name)
{
//sprawdzanie, czy zostały podane wszystkie dane
{
return(false);
}
else
{
}
}
//funkcja zamykająca połączenie
function mysql_close_conn()
{
{
return(true);
}
else
{
return(false);
}
}
//zapytanie
function sql_query($query)
{
//jezeli istnieje plik cashe to nie wykonuj zapytania
if(!$this->cashe_exists($this->cashe_file))
{
{
if( $this->result )
{
return( $this->result );
}
else
{
}
}
else
{
return(false);
}
}
else
{
return(1);
}
}
//zapytanie do tablicy
function sql_fetch_array($result, $mode = '0',$typ = '1')//Dostępne wartości to:1,2,3
{
'1' => MYSQL_ASSOC,
'2' => MYSQL_NUM,
'3' => MYSQL_BOTH
);
//jeżeli istnieje plik cashe to pobierz z niego dane
if(!$this -> cashe_exists($this->cashe_file))
{
if($mode == '0')
{
{
$this->bufor[] = $rows;
}
if($this->cashe_write($this->cashe_file))
{
return($this->bufor);
}
else
{
return(false);
}
}
elseif($mode == '1')
{
{
$this->bufor[] = $rows;
}
return($this->bufor);
}
}
else
{
return($this->bufor);
}
}
//zapisuje do pliku cashe
function cashe_write()
{
//jeżeli plik cashe istnieje, zapisz, jeżeli nie zwróć false
if(!$this -> cashe_exists($this->cashe_file))
{
if(file_put_contents
($this->cashe_dir.$this->cashe_file, serialize($this->bufor))) {
return(true);
}
else
{
return(false);
}
}
}
//usuwa cashe
function delete_cashe()
{
//jeżeli plik cashe istnieje, usuń, jeżeli nie to zwróć false
if($this -> cashe_exists($this->cashe_file))
{
if(unlink($this->cashe_dir.$this->cashe_file)) {
return(true);
}
}
else
{
return(false);
}
}
function getFirstRecord($query)
{
$record = $this->sql_fetch_array($query,1,2);
return $record[0][0];
}
function getFirstRow($query)
{
$row = $this->sql_fetch_array($query,1,3);
return $row[0];
}
function getLastRecord($query)
{
$record = $this->sql_fetch_array($query,1,2);
$rows = count($record)-1; $col = count($record[0
])-1; return $record[$rows][$col];
}
function getLastRow($query)
{
$record = $this->sql_fetch_array($query,1,3);
return $record[$row];
}
function Transaction ($var) {
'fail' => 'ROLLBACK',
'complete' => 'COMMIT',
'start' => 'BEGIN'
);
}
function affected_rows()
{
}
}
?>
Przykład użycia:
<?php
$db = new DB;
$db->cashe_dir = '';
$db->cashe_file = 'xxx.666';
$db->connect('host','dbusr', 'dbpass','dbname');
$query = $db->sql_query('SELECT * FROM USERS WHERE NAME ='usr'');
$array = $db->getFirstRow($query);
print 'Name: '.$array['NAME'].'<br>'; print 'Res: '.$array['RES'].'<BR>';
?>
Zaznaczę tylko, żem początkujący więc głupie błędy są na miejscu

Proszę o uwagi.Klasa jeszcze nie dokończona, chcę się dowiedzieć czy jestem na dobrym tropie
Ten post edytował ziom 8.03.2006, 13:25:36