php专区

 首页 > php专区 > PHP应用 > php类库 > 实用简单的mysql数据库连接类

实用简单的mysql数据库连接类

分享到:
【字体:大 中 小】
导读:
          class DB { //databaseconnection var $con =FALSE; function DB( $MYSQL_HOST =MYSQL_HOST, $MYSQL_USER =MYSQL_USER, $MYSQL_PASS =MYSQL_PASS, $MYSQL_DB =MYSQL_DB) { $this -con=@mysql_connect( $MYSQL_HOST , $MYSQL_USER , $MYSQL_PASS ) or die ( Co...

  1. class DB 
  2. { 
  3.  //database connection 
  4.  var $con = FALSE; 
  5.  
  6.  function DB($MYSQL_HOST=MYSQL_HOST, $MYSQL_USER=MYSQL_USER, $MYSQL_PASS=MYSQL_PASS,$MYSQL_DB=MYSQL_DB) 
  7.  { 
  8.   $this->con = @mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASS) or die("Could not connect to database"); 
  9.  
  10.   if ($this->con) 
  11.   { 
  12.    @mysql_select_db($MYSQL_DB, $this->con) or die ("Could not select database"); 
  13.   } 
  14.  
  15.   return $this->con; 
  16.  } 
  17.  
  18.  
  19.  function Query($sql, $tran = false) 
  20.  { 
  21.  // if (!file_exists(MYSQL_LOG)) 
  22.  // { 
  23.  //  @umask(0); 
  24.  //  @mkdir(MYSQL_LOG, 0777); 
  25.  // } 
  26.  
  27.   // ¼־ 
  28.   //$fp = @fopen(MYSQL_LOG.date("Ymd").".txt", "a"); 
  29.  
  30.   // д־ 
  31.  // @fwrite($fp, date("Y-m-d H:i:s")."|$sql "); 
  32.  // @fclose($fp); 
  33.  
  34.   $this->sql = $sql; 
  35.  
  36.   if ($tran) 
  37.   { 
  38.    $this->result = @mysql_query($this->sql) OR $this->RollBack(); 
  39.    return $this->result; 
  40.   } 
  41.   else 
  42.   { 
  43.       mysql_query("SET NAMES 'utf8'"); 
  44.    //mysql_query("SET NAMES 'gbk'"); 
  45.    $this->result = @mysql_query($this->sql); 
  46.    return $this->result; 
  47.   } 
  48.  } 
  49.  
  50.  
  51.  function RollBack() 
  52.  { 
  53.   $this->Query("ROLLBACK;"); 
  54.   die("MySQL ROLLBACK;"); 
  55.  } 
  56.  
  57.  
  58.  function NumRows($result) 
  59.  { 
  60.   $this->result = $result; 
  61.   return @mysql_num_rows($this->result); 
  62.  } 
  63.  
  64.  
  65.  function FetchRow($result) 
  66.  { 
  67.   $this->result = $result; 
  68.   return @mysql_fetch_row($this->result); 
  69.  } 
  70.  
  71.  
  72.  function FetchArray($result) 
  73.  { 
  74.   $this->result = $result; 
  75.   return @mysql_fetch_array($this->result, MYSQL_ASSOC); 
  76.  } 
  77.  function FetchArray2($result) 
  78.  { 
  79.   $this->result = $result; 
  80.   return @mysql_fetch_array($this->result, MYSQL_BOTH); 
  81.  } 
  82.   
  83.  
  84.  function FetchObject($result) 
  85.  { 
  86.   $this->result = $result; 
  87.   return @mysql_fetch_object($this->result); 
  88.  } 
  89.  
  90.  
  91.  function FreeResult($result) 
  92.  { 
  93.   $this->result = $result; 
  94.   return @mysql_free_result($this->result); 
  95.  } 
  96.  
  97.  function DataSeek($result) 
  98.  { 
  99.  //复位记录集指针 
  100.   $this->result = $result; 
  101.   return mysql_data_seek($this->result,0); 
  102.  } 
  103.   
  104.  function InsertID() 
  105.  { 
  106.   //$this->con = $con; 
  107.   return @mysql_insert_id($this->con); 
  108.  }//开源代码phpfensi.com 
  109.  function Close() 
  110.  { 
  111.   if($this->con) 
  112.   { 
  113.    @mysql_close($this->con); 
  114.   } 
  115.  } 
  116. }
  117.  
分享到:
微信公众号开发之微信公共平台消息回复类
微信公众号开发代码我在网上看到了有不少,其实都是大同小义了都是参考官方给出的demo文件进行修改的,下面给各位分享一个. 初次接触的时候写的一些,有点乱…也没去整理…最近都不想工作了,各种烦,午饭也没吃,就是想表达一下我过的不好,–请忽略个人情绪往下看,代码如下:
php文件打开、创建、读取fopen函数的使用...
php文件打开、创建、读取fopen函数的使用说明 本文章来介绍一个简单的文件操作函数fopen,fopen函数可以打开,读取,并且协助文件保存,下面我来给大家总结一下php文件的操作. 打开文件:fopen 最简单语法如下:fopen(filepath,mode) 下面是打开一个文件的 PHP 代码示例,代码如下: $f = fopen("c...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……