<?phpclass mysql{var $host;var $kullanici;var $sifre;var $tablo;var $idbaglanti = 0;var $idsorgu = 0;function baglan($sunucu,$kullanici,$sifre,$tablo){$this->host = $sunucu;$this->kullanici = $kullanici;$this->sifre = $sifre;$this->tablo = $tablo;$this->idbaglanti = mysqli_connect($sunucu,$kullanici,$sifre,$this->tablo) or die("MySQL'e baglanılamadı: ".mysqli_error($this->idbaglanti));return $this->idbaglanti;}function sorgu($sorgu){$this->idsorgu = @mysqli_query($this->idbaglanti,$sorgu) or die("Sorgu Çalıştırılamadı");return $this->idsorgu;}function sayi(){return mysqli_num_fields($this->idsorgu);}function alanadi($alan){return mysqli_fetch_field_direct($this->idsorgu,$alan)->name;}function cikti(){echo "<table border=1>\n";echo "<tr>\n";for ($i=0;$i<$this->sayi();$i++){echo "<th>".$this->alanadi($i)."</th>\n";}echo "</tr>\n";while ($satir = mysqli_fetch_row($this->idsorgu)) {echo "<tr>\n";for ($i=0;$i<$this->sayi();$i++){echo "<td>".$satir[$i]."</td>\n";}echo "</tr>\n";}echo "</table>\n";}}$m = new mysql();$m->baglan("localhost","root","","php");$m->sorgu("select id,sayfa,tamam from php limit 2");$m->cikti();?>
Çıktısı
border=1idsayfatamam171231