国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

簡單的MYsql操作類

2024-09-04 11:44:17
字體:
供稿:網(wǎng)友
  1. * 1、連接服務(wù)器 2、各類sql動作 
  2. */ 
  3. class mysql{ 
  4.     private $host;  //服務(wù)器地址 
  5.     private $name;  //用戶名稱 
  6.     private $pass;  //密碼 
  7.     private $table//連接數(shù)據(jù)庫教程 
  8.     private $jiema//設(shè)置解碼 
  9.     private $ztime//設(shè)置服務(wù)器的時區(qū) 
  10.     //構(gòu)造函數(shù) 
  11.     function __construct($host,$name,$pass,$table,$jiema,$ztime){ 
  12.         $this -> host  = $host  ; 
  13.       $this -> name  = $name  ; 
  14.       $this -> pass  = $pass  ; 
  15.       $this -> table = $table ; 
  16.   $this -> jiema = $jiema ; 
  17.   $this -> ztime = $ztime ; 
  18.       $this -> connect(); 
  19.      } 
  20.      //數(shù)據(jù)庫連接和設(shè)置 
  21.      function connect(){ 
  22.          $link=@mysql_connect($this->host,$this->name,$this->pass) or die ("連接服務(wù)器失敗"); 
  23.          @mysql_select_db($this->table,$linkor die("連接數(shù)據(jù)失敗"); 
  24.          @mysql_query("set names '$this->jiema'"); 
  25.       @date_default_timezone_set("$this->ztime"); 
  26.      } 
  27.     //執(zhí)行操作 
  28.  function query($sql) { 
  29.      if(!($query = @mysql_query($sql))) $this->show($sql); 
  30.   return $query
  31.  } 
  32.     //顯示信息 
  33.     function show($message = ''$sql = '') { 
  34.   if(!$sqlecho $message
  35.   else echo $message.'<br>'.$sql
  36.  } 
  37.     //取得數(shù)據(jù)集的某個值 
  38.  function result($query,$row,$values) { 
  39.   return @mysql_result($query,$row,$values); 
  40.  } 
  41.     //取得數(shù)據(jù)集的某個值 
  42.  function get_values($table,$row,$values) { 
  43.      $query = $this -> query("select * from $table"); 
  44.   $returnvalues = mysql_result($query,$row,$values); 
  45.   return $returnvalues
  46.  } 
  47.     //取得數(shù)據(jù)集的行數(shù) 
  48.  function num_rows($query) { 
  49.   return @mysql_num_rows($query); 
  50.  } 
  51.     //循環(huán)讀取數(shù)據(jù) 
  52.  function fetch($query) { 
  53.   return @mysql_fetch_array($query); 
  54.  } 
  55.     //最后一次插入紀(jì)錄的id值 
  56.  function insert_id() { 
  57.   return mysql_insert_id(); 
  58.  } 
  59.     //取得數(shù)據(jù)集中的一行 
  60.  function fetch_row($query) { 
  61.   return mysql_fetch_row($query); 
  62.  } 
  63.     //插入一條數(shù)據(jù) 
  64.     function fn_insert($table,$name,$value){ 
  65.      if($this->query("insert into $table ($name) values ($value)")){ 
  66.       return true; 
  67.   }else
  68.       return false; 
  69.   } 
  70.     } 
  71.     //插入任意數(shù)據(jù) 
  72.     function sql_insert($tbname,$postvalues){ 
  73.         foreach ($postvalues as $key => $value) { 
  74.    $postvalue .= "`".$key."`".","
  75.    $sqlvalue .= "'".$value."',"
  76.   } 
  77.   $sqlfield = mb_substr("$postvalue",0,-1,'gbk'); 
  78.   $sqlvalue = mb_substr("$sqlvalue",0,-1,'gbk'); 
  79.   if($this-> fn_insert("$tbname","$sqlfield","$sqlvalue")){ 
  80.       return true; 
  81.   }else
  82.       return false; 
  83.   } 
  84.  }  
  85.     //修改萬能數(shù)據(jù) 
  86.     function sql_update($table,$postvalues,$wwhere){ 
  87.   foreach ($postvalues as $key=>$value) { 
  88.    $sqlfield .= $key."="."'".$value."'".","
  89.   } 
  90.   $sqlfield= mb_substr("$sqlfield",0,-1,'gbk'); 
  91.   if($this->fn_update("$table","$sqlfield","$wwhere")){ 
  92.       return true; 
  93.   }else
  94.       return false; 
  95.   } 
  96.  } 
  97.     //修改一條數(shù)據(jù) 
  98.     function fn_update($table,$value,$wwhere){ 
  99.      if($this->query("update $table set $value where $wwhere")){ 
  100.       return true; 
  101.      }else
  102.       return false; 
  103.   } 
  104.     } 
  105.     //刪除一條數(shù)據(jù) 
  106.     function sql_delete($table,$wwhere){ 
  107.      if($this->query("delete from $table where $wwhere")){ 
  108.       return true; 
  109.   }else
  110.       return false; 
  111.   } 
  112.  } 
  113.  //關(guān)閉數(shù)據(jù)連接 
  114.     function close() { 
  115.   return mysql_close(); 
  116.  }//開源代碼Vevb.com 
  117. $db =  new mysql($location['host'],$location['hostname'],$location['hostpass'],$location['table'],$location['jiema']

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 溧水县| 扎鲁特旗| 巴林左旗| 延津县| 曲松县| 会宁县| 绵阳市| 历史| 商河县| 屏东县| 梨树县| 通江县| 海口市| 文昌市| 老河口市| 湾仔区| 游戏| 岳普湖县| 长治市| 读书| 通山县| 延长县| 丰都县| 池州市| 玉溪市| 苏州市| 美姑县| 武清区| 宜章县| 香港| 惠水县| 梅河口市| 称多县| 博客| 绵阳市| 闸北区| 陈巴尔虎旗| 怀远县| 积石山| 湖北省| 汪清县|