Merhaba, Ziyaretçi. Lütfen giriş yapın veya üye olun.
Aktivasyon mailiniz gelmediyse buraya tıklayın.
Mayıs 13, 2008, 06:11:55 pm
41812 Mesaj 9080 Konu Gönderen: 17479 Üye
Son üye: umit_cbn
Turk-Php.Com Forum  |  Yardım Forumları  |  PHP Yardım Forumu  |  PHP Class Deposu  |  mysql sınıfı « önceki sonraki »
Sayfa: [1] Yazdır
Yazan Konu: mysql sınıfı  (Okunma Sayısı 691 defa)
enginna
PHP Memuru
***
Offline Offline

Mesaj Sayısı: 836



Üyelik Bilgileri
mysql sınıfı
« : Aralık 03, 2006, 12:31:27 pm »

force mysql'den alıntıdır.
Kod:
<?php
class core_mysql {
  var 
$mysql_connect;
  var 
$mysql_result;
  function 
core_mysql ($host$user$pass$db) {
    if ( !(
$this->mysql_connect mysql_connect ($host$user$pass)) ) {
      
trigger_error ("Cannot connect to MySQL");
    }
    if ( !
mysql_select_db ($db$this->mysql_connect) ) {
      
trigger_error ("Unable to select database");
    }
  }
  
/*
    USAGE: query ('SELECT user_id, user_name FROM core_users WHERE user_id = %d', 1);
    This function takes exactly the same format as the sprintf funciton in php - the difference
    being that every parameter from the 2nd onward are fired thru the mysql_real_escape string
    function to lessen the chance of an SQL Injection attack (never good, eh?)
  */

  
function query () {
    
$argv func_get_args ();
    
$argc func_num_args ();
    
$sql $argv[0];
    
$argp = array();
    for (
$argn 1$argn $argc$argn++) {
      
$argp[] = mysql_real_escape_string ($argv[$argn], $this->mysql_connect);
    }
    if ( !(
$this->mysql_result mysql_query (vsprintf ($sql$argp), $this->mysql_connect)) ) {
      
trigger_error ("Unable to execute SQL Query: " mysql_error ());
    }
    return 
$this->mysql_result;
  }
}

/* Sample Code */

$db_conn = new core_mysql ('localhost''user''pass''db_name');

$result $db_conn->query ('SELECT a, b, c FROM table WHERE a = "%s", b = %d, c = 1''blah'3);

/* Loop for going through the $result */
?>
Logged

bir fikrim var. internetteki siteleri kaydeden bir site yapalım. isteyen bu siteler içinde arama yapsın. sitenin domaini'de google.com olsun nasıl?   :D
Sayfa: [1] Yazdır 
« önceki sonraki »
Gitmek istediğiniz yer: