<?php class SQLKatman { var $sunucu; var $kullaniciadi; var $sifre; var $veritabaniadi; var $link; function SQLKatman ($sunucu = "", $kullaniciadi = "", $pass = "", $veritabaniadi = "") { $this->sunucu = $sunucu; $this->kullaniciadi = $kullaniciadi; $this->sifre = $pass; $this->veritabaniadi = $veritabaniadi; $this->baglan(); } function baglan(){ $this->link=mysqli_connect($this->sunucu,$this->kullaniciadi,$this->sifre,$this->veritabaniadi); mysqli_set_charset($this->link, "utf8"); } function close(){ return mysqli_close($this->link); } function sorgu($sorgu){ $this->rs=mysqli_query($this->link,$sorgu); if (!$this->rs){ echo("Hata: Hatalı sorgu \"".$sorgu."\"...<br>"); echo("Hata: ".mysqli_errno($this->link)."<br>"); die("Hata: ".mysqli_error($this->link)."<br>"); }else{ return $this->rs; } } function veri_ara ($row = 0) { return mysqli_data_seek($this->rs,$row); } function dizi_getir($rs=""){ if($rs==""){$rs=$this->rs;} $this->row=mysqli_fetch_array($rs); return $this->row; } function birles_getir($rs=""){ if($rs==""){$rs=$this->rs;} $this->row=mysqli_fetch_assoc($rs); return $this->row; } function nesne_getir($rs=""){ if($rs==""){$rs=$this->rs;} $this->row=mysqli_fetch_object($rs); return $this->row; } function satir_say($rs=""){ if($rs == ""){$rs=$this->rs;} $rs = $this->rs; return mysqli_num_rows($rs); } function etkilenen_satir() { return mysqli_affected_rows($this->link); } function serbest_sonuc($rs = "") { if($rs == ""){$rs=$this->rs;} $rs = $this->rs; return mysqli_free_result($rs); } } $s=new SQLKatman("localhost","root","","php"); $s->sorgu("select * from php where id=1"); print_r($s->dizi_getir());echo "<br>"; $s->sorgu("select * from php where id=1"); print_r($s->birles_getir());echo "<br>"; $s->sorgu("select * from php where id=1"); print_r($s->nesne_getir());echo "<br>"; $s->sorgu("select * from php where id=1"); print_r($s->satir_say());echo "<br>"; $s->sorgu("select * from php where id=1"); print_r($s->etkilenen_satir());echo "<br>"; $s->sorgu("select * from php where id=1"); print_r($s->serbest_sonuc()); $s->sorgu("select * from php where id=1"); var_dump($s->veri_ara(2)); ?>
Çıktısı
Array ( [0] => 1 [id] => 1 ) Array ( [id] => 1 ) stdClass Object ( [id] => 1 ) 1 1 bool(false)