Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)

Paste

Pasted as PHP by zumsuk ( 15 years ago )
<?php header('Content-Type: text/html; charset=utf-8');

//  /--------------------------------------------------------------\
//  |         Bu sınıf Emre Çetin tarafından kodlanmıştır          |
//  |             iletişim : ayro26@gmail.com                      |
//  |         Dikkat: php 5 ve mysqli olmadan çalışmaz !           |
//  |--------------------------------------------------------------|
//  |          Örnek kullanım aşşağıda gösterilmiştir              |
//  \--------------------------------------------------------------/
/*
@veri tabanı sınıfımızı yaratalım;
$vt = new vt(); 

@host ve veritabanına bağlanalım;
$vt->baglan('localhost','root','','tarcan');

@sorgu cekelim (listelemek veya tek sorgu çekmek için)
$get = $vt->gor("select * from uyeler");

@ çektiğiniz sorgunun hepsini görmek için şöyle birşey yapabilirsiniz.
echo '<pre>';print_r($get);echo'</pre>';

@isterseniz tek tek şu şekilde bakabilirsiniz;1. kayıdın (id değil) nick'ine bakabilirsiniz.
$get[1]['nick'];

@veri eklemek , silmek, düzenlemek için; [soru kısmına update vs.. şeklinde normalde gireceğiniz sql sorgusunu yazın]
$vt->sql('sql sorgunuz');

@hata varsa ekrana bastıracaktr
$vt->sonuc();
----------------------------

## Ekstralar ##

@Eğer kaç sonuç bulunduğunu merak ediyorsanız
echo $vt->kacsonuc;

@html süzgeci için;
$vt->suz($degisken);

@sql injection önlemi için;
$vt->guvenlik($degisken);

*/

if (version_compare(PHP_VERSION, '5.0.0')===-1)
            die('<b>VT Error:</b> php 5 neden kurmuyorsun arkadaşım ?');

        if (!extension_loaded('mysqli'))
            die('<b>Hata:</b> mysqli olmadan çalışmaz !');

class VT{
    protected $server = 'localhost'; // server : @localhost
    protected $suser = 'root'; // server kullanıcısı : @root
    protected $spass = ''; // server şifresi (varsa)
    public $db = 'tarcan'; // veritabanı @ sonradan database seçmek isterseniz $vt->db='yenidb'; şeklinde kullanabilirsiniz
    
    public $durum; // mysqli durumu
    public $sorgu; // sql sorgusu
    public $sor; // mysql_query ile birleştirilen hali
    public $kacsonuc;
    
    protected $hata = False; 
    protected $hatalar = array();
    protected $sonuc = array();
    
    function baglan(){
        $this->durum = @mysqli_connect($this->server,$this->suser,$this->spass);
        if(!mysqli_set_charset($this->durum, "utf8")){
            $this->hatalar[] = 'Charset ayarlarken sıkıntı çıktı';
            $this->hata=True;
        }
        if( ! $this->durum ){
            $this->hatalar[] = 'Mysql Bağlantısında sorun var.Server, kullanıcı ve şifreyi doğru girin';
            $this->hata=True;
        }
        $this->dbsec($this->db);
    }
    
    function dbsec($db){
        if(!mysqli_select_db($this->durum,$db)){
            $this->hatalar[] = 'Database seçilemedi.Adı kontrol edin';
            $this->hata=True;
        }
    }
    
    function guvenlik($g){
        return mysqli_real_escape_string($this->durum,$g);
    }
    
    function suz($a){
        return htmlspecialchars($a,ENT_QUOTES,"UTF-8");
    }
    
    function gor($a){
        if (empty($this->durum)){
           if(array_search('vtbag',$this->hatalar) === False)
                $this->hatalar[] = 'Veritabanına Bağlanın';
            $this->hata = True;
            return false;
        }
        $this->sorgu = $this->guvenlik($a);
        
        if(!$this->durum){
            if(array_search('vtbag',$this->hatalar) === False)
                $this->hatalar[] = 'Veritabanına Bağlanın';
            $this->hata = True;
            return false;
        }
        
        $this->sor = @mysqli_query($this->durum,$this->sorgu);
        
        if($this->sor===False){
            $this->hatalar[] = mysqli_error($this->durum);
            $this->hata = True;
            return false;
        }
        
        $sonuclar=array(0=>'Sonuçlar;');
        while ($g = mysqli_fetch_object($this->sor)) {
            $sonuclar[] = get_object_vars($g);
        }
        $this->kacsonuc = count($sonuclar)-1;
        mysqli_free_result($this->sor);
        return $sonuclar;
    }
    
    function sql($a){
        if (empty($this->durum)){
            if(array_search('vtbag',$this->hatalar) === False)
                $this->hatalar[] = mysqli_error($this->durum);
            $this->hata = True;
            return false;
        }
        if(!mysqli_query($this->durum,$a)){
            $this->hatalar[] = mysqli_error($this->durum);
            $this->hata=True;
        }
    }
    
    function hata(){
        if($this->hata=True){
            $hatasay = sizeOf($this->hatalar);
            if($hatasay>0){
                echo $hatasay,' hata bulunmuştur.<br><br><b>Hatalar</b>;<br>';
                foreach($this->hatalar as $hata){
                    echo '-',$hata,'<br>';
                }
            }
        }
    }
    
    function sonuc(){
        $this->hata();
    }
    
    function __destruct(){
        if( $this->durum ){
            mysqli_close($this->durum);
        }
    }
}
?>

 

Revise this Paste

Children: 32472
Your Name: Code Language: