Basit Mysqli Veritabanı Erişim ve Tablolu Çıktı Sınıfı

PHP
48 lines
<?php
class 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();
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

HTML
17 lines
<table border=1>
<tr>
<th>id</th>
<th>sayfa</th>
<th>tamam</th>
</tr>
<tr>
<td>1</td>
<td>7</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>1</td>
</tr>
</table>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Sizin Değerli Görüşlerinize İhtiyacımız Var.