Sql Uygulaması
__uygulama.php
<?php
class __mysql
{
public $host = "127.0.0.1";
public $username = "root";
public $password ="1";
public $db = "zb";
public $connect;
function __construct()
{
try
{
$this->connect = @mysql_connect($this->host, $this->username, $this->password);
if($this->connect)
{
mysql_select_db($this->db,$this->connect);
echo "Mysql Baglanti Ýþlemi Basari Ile Gerceklesmistir.";
}else{
throw new exception("Sunucumuz Güncelleme Asamasindadir. Lutfen Daha Sonra Tekrar Deneyiniz");
}
}
catch(Exception $e)
{
echo $e->getMessage();
}
}
function SQL($Sorgu)
{
return mysql_query($Sorgu);
}
function VeriBas($Sonuc)
{
$SutunSayisi = mysql_num_fields($Sonuc);
$Html = "<table border=1><tr>";
for($i=0;$i<$SutunSayisi;$i++)
{
$Html.="<td><strong>".mysql_field_name($Sonuc,$i)."</strong></td>";
}
while($Oku = mysql_fetch_array($Sonuc,MYSQL_BOTH))
{
$Html.="<tr>";
for($i=0;$i<$SutunSayisi;$i++)
{
$Html.="<td>".$Oku[$i]."</td>";
}
$Html.="</tr>";
}
$Html.="</table>";
echo $Html;
}
}
?>
index.php
<?php
require_once("./__uygulama.php");
$Conn = new __mysql();
echo "<br><br><b><font color = "000FFF">select * from urunler</font></b>";
echo "<b><br>Urunlerin listesi</b>";
$Conn->VeriBas($Conn->SQL("select * from urunler "));
echo "<hr>";
echo "<b><font color = "000FFF">select * from calisanlar</font></b>";
echo "<b><br>Calisanlarin Listesi</b>";
$Conn->VeriBas($Conn->SQL("select * from calisanlar"));
echo "<hr>";
echo "<b><font color = "000FFF">select * from calisanlar where adi like '%a%'</font></b>";
echo "<b><br>Isminde a harfi geçen calisanlar";
$Conn->VeriBas($Conn->SQL("select * from calisanlar where adi like '%a%'"));
echo "<hr>";
echo "<b><font color = "000FFF">select * from calisanlar where adi like '_a%'</font></b>";
echo "<b><br>Isminin Ikinci harfi a olan calisanlar";
$Conn->VeriBas($Conn->SQL("select * from calisanlar where adi like '_a%'"));
echo "<hr>";
echo "<b><font color = "000FFF">select * from calisanlar where adi like 'b%' order by adi</font></b>";
echo "<b><br>Isminin birinci harfi b olan calisanlarin alfabetik si;ralanmasi;";
$Conn->VeriBas($Conn->SQL("select * from calisanlar where adi like 'b%' order by adi"));
echo "<hr>";
echo "<b><font color = "000FFF">select count('id') from urunler</font></b>";
echo "<b><br>count";
$Conn->VeriBas($Conn->SQL("select count('id') from urunler"));
echo "<hr>";
echo "<b><font color = "000FFF">select sum(urunsayisi) from zb</font></b>";
echo "<b><br>urun sayisinin toplami ";
$Conn->VeriBas($Conn->SQL("select sum(urunsayisi) from zb"));
echo "<hr>";
echo "<b><font color = "000FFF">select avg(urunsayisi) from zb</font></b>";
echo "<b><br>urun sayisinin ortalamasý ";
$Conn->VeriBas($Conn->SQL("select avg(urunsayisi) from zb"));
echo "<hr>";
echo "<b><font color = "000FFF">select max(urunsayisi) from zb</font></b>";
echo "<b><br>en fazla olan ürün sayisi ";
$Conn->VeriBas($Conn->SQL("select max(urunsayisi) from zb;"));
echo "<hr>";
echo "<b><font color = "000FFF">select min(urunsayisi) from zb</font></b>";
echo "<b><br>en az olan ürün sayisi ";
$Conn->VeriBas($Conn->SQL("select min(urunsayisi) from zb;"));
echo "<hr>";
//LOWER()
echo "<b><font color = "000FFF">select lower('MERHABA')</font></b>";
echo "<b>Buyuk Karakterlerin Küçük Karaktere Çevrilmesi</b>";
$Conn->VeriBas($Conn->SQL("select lower('MERHABA')"));
echo "<hr>";
//UPPER()
echo "<b><font color = "000FFF">select upper('merhaba')</font></b>";
echo "<b>Kucuk Karakterlerin Buyuk Karaktere Çevrilmesi</b>";
$Conn->VeriBas($Conn->SQL("select upper('merhaba')"));
echo "<hr>";
//LENGTH()
echo "<b><font color = "000FFF">SELECT LENGTH('text')</font></b>";
echo "<b><br>Karakter uzunluðunun sayi degeri</b>";
$Conn->VeriBas($Conn->SQL("SELECT LENGTH('text')"));
echo "<hr>";
//LEFT()
echo "<b><font color = "000FFF">select left('merhaba', 2)</font></b>";
echo "<b><br>Soldan istenilen sayýda veri alma</b>";
$Conn->VeriBas($Conn->SQL("select left('merhaba', 2)"));
echo "<hr>";
//RIGHT()
echo "<b><font color = "000FFF">select right('merhaba', 2)</font></b>";
echo "<b><br>Saðdan istenilen sayýda veri alma</b>";
$Conn->VeriBas($Conn->SQL("select right('merhaba', 2)"));
echo "<hr>";
//ROUND()
echo "<b><font color = "000FFF">SELECT ROUND( 1.66 )</font></b>";
echo "<b><br>küsürlü sayýlarý yuvarlama fonksiyonu</b>";
$Conn->VeriBas($Conn->SQL("SELECT ROUND( 1.66) ;"));
echo "<hr>";
//MOD()
echo "<b><font color = "000FFF">SELECT MOD( 2,9)</font></b>";
echo "<b><br>mod alimi</b>";
$Conn->VeriBas($Conn->SQL("SELECT MOD( 2,9);"));
echo "<hr>";
//CONCAT
echo "<b><font color = "000FFF">select concat(urun_adi,urunu_satan) from urunler;</font></b>";
echo "<b><br>urun_adi ile urunu_satan larýn birleþimi </b>";
$Conn->VeriBas($Conn->SQL("select concat(urun_adi,urunu_satan) from urunler where id between 1 and 6;"));
echo "<hr>";
?>
Yorumunuzu Ekleyin