buda mysql verisyonu bir önceki mssql versiyonu idi <?php
/** * @author memo * @copyright 2007 */ class MySQL{ private $host, $user, $password, $newLink, $database; private $conn, $resource; private $printErrorEnabled = false; public $errorInfo; private $errorLogFile; private $query = ''; //sayfalama ile ilgili private $toplamkayit,$toplamsayfa,$pQuery='',$limit=20,$baslangic,$url,$urlek='&p=',$kacadetlink=5, $sayfano; public $ilk,$son,$ileri,$geri,$linkler,$printlink,$printtoplamsayfa; function __construct($PrintErrorEnabled = false,$ErrorLogFile = false,$use_globalConn=true,$Host = DB_HOST, $User = DB_USER, $Password = DB_PASS, $Database = DB_NAME, $NewLink = false ){ $this->host = $Host; $this->user = $User; $this->password = $Password; $this->database = $Database; $this->newLink = $NewLink; $this->printErrorEnabled = $PrintErrorEnabled; //$this->errorLogFile = $ErrorLogFile; global $root_dir; $this->errorLogFile = $root_dir.'logs/'.date("m.Y").'_mde.log'; if($use_globalConn){ global $MYSQL_CONN; $this->conn = $MYSQL_CONN; } else { if($this->connect()) $this->select_db(); $this->query("SET NAMES 'latin5'"); $this->query("SET CHARACTER SET 'latin5'"); // $this->query("COLLATE 'latin5_turkish_ci'"); } }//end constructor function connect(){ $this->conn = mysql_connect($this->host, $this->user, $this->password, $this->newLink); if(!$this->conn){ $this->errorInfo = 'MYSQL BAĞLANTI HATASI: '.mysql_error($this->conn); $this->printError(); exit();/////////////////// return false; } return true; }//end method connect() function select_db(){ if(!...@mysql_select_db($this->database, $this->conn)){ $this->errorInfo = 'DATABASE BAĞLANTI HATASI: '.mysql_error(); $this->printError(); exit();///////////////////////////////////////// return false; } return true; }//end method select_db() function query($Query){ $this->query = $Query; $this->resource = @mysql_query($Query,$this->conn); if($this->resource === false){ $this->errorInfo = 'MYSQL QUERY HATASI: '.mysql_error($this->conn); $this->printError(); return false; } return $this->resource; }//end method query() function result($RowNum=0, $Field=0){ if(@get_resource_type($this->resource) === false){ $this->errorInfo = 'MySQL::result() metoduna gönderdiğiniz değişken, bir mysql sonuç değişkeni değildir!'; $this->printError(); return false; } $res = mysql_result($this->resource,$RowNum,$Field); if($res === false){ $this->errorInfo = 'mysql_result() Hatasi: '.mysql_error(); $this->printError(); return false; } return $res; }//end method result() /** * bu fonksiyonu if( ? === false ) şeklinde kullnabilirsin */ function get_value($Query, $RowNum=0, $Field=0){ //echo "a"; $this->query = $Query; $res = @mysql_query($Query,$this->conn); //echo $res; if($res === false){ $this->errorInfo = 'MYSQL QUERY HATASI: '.mysql_error($this->conn); $this->printError(); return false; } else { if(@mysql_num_rows($res) <= 0){ return ''; } $result = @mysql_result($res,$RowNum,$Field); if($result === false){ $this->errorInfo = 'mysql_result() Hatasi: '.mysql_error(); $this->printError(); return false; } return $result; } }//end method get_value() /** * bu fonksiyonu if( ? === false ) şeklinde kullanma */ function get_values($Query){ $this->query = $Query; $res = @mysql_query($Query,$this->conn); if($res === false){ $this->errorInfo = 'MYSQL QUERY HATASI: '.mysql_error($this->conn); $this->printError(); return false; } else { if(@mysql_num_rows($res) <= 0){ return ''; } return @mysql_fetch_assoc($res); } }//end method get_values() function affected_rows(){ return mysql_affected_rows($this->conn); }//end method affected_rows() function num_rows(){ $no = @mysql_num_rows($this->resource); if($no === false){ $this->errorInfo = "mysql_num_rows() Hatası: ".mysql_error($this->conn); $this->printError(); return false; } return $no; }//end method num_rows() function inserted_id(){ $id = mysql_insert_id($this->conn); if($id === false){ $this->errorInfo = 'MySQl Bağlantısı Yok: '.mysql_error($this->conn); $this->printError(); return false; } return $id; }//end method inserted_id() function fetch_assoc(){ if(@get_resource_type($this->resource) === false){ $this->errorInfo = 'MySQL::fetch_assoc() metoduna gönderdiğiniz değişken, bir mysql sonuç değişkeni değildir!'; $this->printError(); return false; } return mysql_fetch_assoc($this->resource); }//end method fetch_assoc() function fetch_row(){ if(@get_resource_type($this->resource) === false){ $this->errorInfo = 'MySQL::fetch_row() metoduna gönderdiğiniz değişken, bir mysql sonuç değişkeni değildir!'; $this->printError(); return false; } return mysql_fetch_row($this->resource); }//end method fetch_row() /** mysql_fetch_aray() fonksiyonunu çalıştırır. * @param $ResultType: MYSQL_BOTH (default), MYSQL_ASSOC, MYSQL_NUM */ function fetch_array($ResultType = MYSQL_BOTH){ if(@get_resource_type($this->resource) === false){ $this->errorInfo = 'MySQL::fetch_array() metoduna gönderdiğiniz değişken, bir mysql sonuç değişkeni değildir!'; $this->printError(); return false; } return mysql_fetch_array($this->resource,$ResultType); }//end method fetch_array() function close(){ if(!mysql_close($this->conn)){ $this->errorInfo = 'MYSQL KAPAMA HATASI: '.mysql_error($this->conn); $this->printError(); return false; } return true; }//end method close() function printError(){ if($this->printErrorEnabled) echo $this->errorInfo.' || (QUERY:::'.$this->query.')'.'<br>'; if($this->errorLogFile){ $f = @fopen($this->errorLogFile,'a'); @fwrite($f, date('d.m.Y H:i:s')."- ".$this->errorInfo.' || (QUERY:::'.$this->query.')'."\r\n"); @fclose($f); } }//end method printError() function printQuery(){ echo $this->query; } /** * Sayfalama Fonksiyonu * Bu fonksiyon ile hem sayfalama hemde kayıtları cekebilirsiniz. * Mysql_feth_array fonksiyonunu kullanır. * * @param String tüm kayıtları cekecek sql * @param String Sayfalama yapılacak url * @param int her sayfada kaç kayıt cekilecek * @param int her sayfada kaç adet sayfalama linki görünecek * @param int aktif sayfa numarası $_GET[p] şeklinde olmalı */ function Sayfalama($query,$url,$limit=20,$kacadetlink,$sayfano){ $this->pQuery = $query; $this->url = $url; $this->limit = $limit; $this->kacadetlink = $kacadetlink; $this->sayfano = ($sayfano==null || $sayfano==1) ? 1 : $sayfano; $this->query($query); $this->toplamkayit = $this->num_rows(); $this->toplamsayfa = ceil($this->toplamkayit / intval($limit)); $this->printtoplamsayfa = $this->toplamsayfa; $this->baslangic = intval($this->sayfano-1) * intval($limit); $this->query = $this->pQuery.' LIMIT '.$this->baslangic.', '.$this->limit; $this->query($this->query); if($this->toplamsayfa <= $this->kacadetlink){ if($this->toplamkayit <= $this->limit){ $ilksayfa = 1; $sonsayfa = $this->toplamsayfa; }else{ $ilksayfa = 1; $sonsayfa = $this->toplamsayfa; } }else{ if($this->sayfano < intval($this->kacadetlink / 2) + 1){ $ilksayfa = 1; $sonsayfa = $this->kacadetlink; }else{ $ilksayfa = $this->sayfano - intval($this->kacadetlink / 2); $sonsayfa = $this->sayfano + intval($this->kacadetlink / 2); if($sonsayfa > $this->toplamsayfa) $sonsayfa = $this->toplamsayfa; } } for($i =$ilksayfa; $i<= $sonsayfa; $i++){ if($i==$this->sayfano){ $this->linkler .='<span id=pasiflink>'.$i.'</span>'; }else{ $this->linkler .='<span><a href="'.$this->url.$this->urlek.$i.'">'.$i.'</a></span> '; } } if($this->sayfano > 1){ $this->geri = '<span><a href="'.$this ->url.$this->urlek.($this->sayfano - 1).'"><Geri</a></span> '; } if($this->sayfano < $this->toplamsayfa){ $this->ileri = '<span><a href="'.$this->url.$this->urlek.($this->sayfano + 1).'">İleri ></a></span> '; } if($this->sayfano > 1){ $this->ilk = '<span><a href="'.$this->url.$this->urlek.'1"><< İlk</a></span> '; } if($this->sayfano < $this->toplamsayfa){ $this->son = '<span><a href="'.$this->url.$this->urlek.$this->toplamsayfa.'">Son >></a></span> '; } $this->printlink = $this->ilk . $this->geri. $this->linkler . $this->ileri. $this->son; } static function getField($table, $field, $condition, $connectedToDB = false){ if (!$connectedToDB) { if (!...@mysql_connect("localhost","root", "")) { return false; } if (!...@mysql_select_db("dukkan")) { return false; } } if (!($res = @mysql_query("SELECT $field FROM $table WHERE $condition"))) { return false; } if (@mysql_fetch_row($res)) { return mysql_result($res,0,0); } return false; }//end method getField() }//end class MySQL ?> _______________________________________________ Linux-programlama mailing list Linux-programlama@liste.linux.org.tr http://liste.linux.org.tr/mailman/listinfo/linux-programlama Liste kurallari: http://liste.linux.org.tr/kurallar.php