티스토리 뷰

1번 방법 

$mysql_last_query = ""; //this var contains the last mysql query
function query($sql, $args) {
  #sintax: query("query", "arg1", "arg2", "argn"); EXAMPLE: query("select * from %s", $_GET["table"]);   global $mysql_last_query;   $args = func_get_args();
  if(($num = func_num_args()) > 1)
  $sql = call_user_func_array("sprintf", $args);   $mysql_last_query = $sql;   return mysql_query($sql); }

function select($table, $what = "*", $where = "", $limit = ""){   #this function is a "shortcut" for mysql select EXAMPLE: select("blah"); //SELECT * FROM blah and so on   return mysql_query("SELECT ".$what." FROM ".$table.($where == "" ? "":(" WHERE ".$where)).($limit == "" ? "":(" LIMIT ".$limit))); }

2번 방법

function mysql_insert($table, $inserts) {
  $values = array_map('mysql_real_escape_string', array_values($inserts));
  $keys = array_keys($inserts);
  return mysql_query('INSERT INTO `'.$table.'` (`'.implode('`,`', $keys).'`) VALUES (\''.implode('\',\'', $values).'\')');
} 

// For example: mysql_insert('cars', array(   'make' => 'Aston Martin',   'model' => 'DB9',   'year' => '2009', ));
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함