• 20-11-2012, 19:47:01
    #1
    Kişisel bir proje için yazdığım veritabanı sınıfım;
    <?php
    
    class db
    {
    	private $server = ''; // Mysql location
    	private $user = ''; // Mysql user name
    	private $pass = '' ; // Mysql password
    	private $db = ''; // Mysql database name
    	private	$connect; // Connection varible
    	
    	function __construct()
    	{
    		$this->connect = mysql_connect($this->server,$this->user,$this->pass);
    			
    		if($this->connect){	
    			mysql_select_db($this->db);	
    			return true;
    		}else{
    			return false;	
    		}
    	}
    	
    	function query($query)
    	{
    
    		$run = mysql_query($query,$this->connect);
    		if($run){
    			return true;	
    		}else{
    			return false;
    		}
    	}
    	
    	function turn($veriable)
    	{
    	
    		if($veriable){
    			return true;	
    		}else{
    			return false;
    		}	
    		
    	}
    	
    	function count($data,$operator)
    	{
    		
    				$count = count($data);
    		
    		if($count > 1){
    			
    		foreach ($data as $key => $value){
    			
    			$where[] = $key.' = "'.$value.'"';
    			
    		}
    		
    		return $where = implode(' '.$operator.' ' , $where);
    		
    		
    			
    		}else{
    		
    		$keys = array_keys($data);
    		$values = array_values($data);
    		
    		return $where = $keys[0] .' = "'.$values[0].'"';
    		
    		}	
    	
    	}	
    	
    	function insert(array $data ,$table)
    	{
    			if(count($data) > 1){
    			
    				$datas = implode(',',array_keys($data));
    				$values = implode('","',array_values($data));
    			
    			}else{
    			
    				foreach ($data as $dataa => $valuee){
    					
    					$datas = $dataa;
    					$values = $valuee; 
    					
    				}
    			
    			}
    			
    			$insert = $this->query('INSERT INTO '.$table.' ('.$datas.') VALUES ("'.$values.'")');
    			
    			return $this->turn($insert);
    	
    	}
    	
    	function delete(array $data ,$table)
    	{
    	
    		$where = $this->count($data,'AND');	
    		
    		$delete = $this->query('DELETE FROM '.$table.' WHERE '.$where.'');	
    		
    		return $this->turn($delete);
    		
    	}
    	
    	function update(array $data ,array $where, $table)
    	{
    		$set = $this->count($data,',');
    		$where = $this->count($where,'AND');	
    		
    		$update = $this->query('UPDATE '.$table.' SET '.$set.' WHERE '.$where.' ');
    		
    		return $this->turn($update);
    	}
    	
    	function __destruct()
    	{
    		
    		mysql_close();	
    		
    	}
    	
    	
    
    }
    
    
    
    ?>
    Kullanımı;

    <?php
    include('db.php');
    $db = new db;
    
    $db->insert(array('hücre' => 'veri'), 'veritabani'); // Veri ekle
    $db->update(array('hücre' => 'veri'),array('değişecek hücre' => 'değişecek veri'), 'veritabani'); // Veri güncellle
    $db->delete(array('hücre' => 'veri'), 'veritabani'); //Veri sil
    
    ?>
  • 21-11-2012, 21:00:40
    #2
    Üyeliği durduruldu
    bir cache, debug ve bağlantı zamanlayıcı dahil etmeni öneririm yiit
  • 23-11-2012, 01:50:37
    #3
    SefaCan adlı üyeden alıntı: mesajı görüntüle
    paylaşım için tşkler fakat gereksiz bence...
    katılıyorum sana kardeşim ama yinede arkadaşın ellerine sağlık belki geliştirir...
  • 24-11-2012, 03:58:27
    #4
    Kimlik doğrulama veya yönetimden onay bekliyor.
    birde $veriable yi $variable yapmak lazım hocam
  • 24-11-2012, 04:27:29
    #5
    Suerte adlı üyeden alıntı: mesajı görüntüle
    birde $veriable yi $variable yapmak lazım hocam
    Yerinde bir tespit.
  • 24-11-2012, 04:33:29
    #6
    Suerte adlı üyeden alıntı: mesajı görüntüle
    birde $veriable yi $variable yapmak lazım hocam
    headshot
  • 24-11-2012, 04:39:44
    #7
    oradaki değişken $sllaeble de olsa çalişir
  • 24-11-2012, 13:34:20
    #8
    tiklagel adlı üyeden alıntı: mesajı görüntüle
    oradaki değişken $sllaeble de olsa çalişir
    çok ciddimisin bu konuda kardeş
  • 24-11-2012, 16:09:01
    #9
    @phpClass, yapıcı eleştirin için konuyu açan arkadaş adına ben sana teşekkür ederim.

    Diğer arkadaşlara söyleyecek söz yok, insanı r10'dan soğutuyorsunuz. Yazık..