|
|
|
Author
|
Topic: mysql sınıfı (Read 786 times)
|
|
enginna
|
force mysql'den alıntıdır. <?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? 
|
|
|
|
 |
|