ホームページ  >  記事  >  バックエンド開発  >  実践的でシンプルな mysql データベース接続 class_PHP チュートリアル

実践的でシンプルな mysql データベース接続 class_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-13 17:04:03872ブラウズ

宀单的mysql教程データベース库教程接类
クラスDB
{
 //データベース接続
 var $con = FALSE;

関数 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) または die("データベースに接続できませんでした");

if ($this->con)
  {
   @mysql_select_db($MYSQL_DB, $this->con) or die (「データベースを選択できませんでした」);
  }

$this->conを返す
 }


 関数クエリ($sql, $tran = false)
 {
 // if (!file_exists(MYSQL_LOG))
 // {
 // @umask(0);
 // @mkdir(MYSQL_LOG, 0777);
 // }

// 1/4
  //$fp = @fopen(MYSQL_LOG.date("Ymd").".txt", "a");

// д־
 // @fwrite($fp, date("Y-m-d H:i:s")."|$sqlrn");
 // @fclose($fp);

$this->sql = $sql;

if ($tran)
  {
   $this->result = @mysql_query($this->sql) OR $this->RollBack();
   $this->result;
を返す   }
  それ以外
  {
      mysql_query("SET NAMES 'utf8'");
   //mysql_query("SET NAMES 'gbk'");
   $this->result = @mysql_query($this->sql);
   $this->result;
を返す   }
 }


 関数 RollBack()
 {
  $this->Query("ROLLBACK;");
  die("MySQL ROLLBACK;");
 }


 関数 NumRows($result)
 {
  $this->結果 = $結果;
  return @mysql_num_rows($this->result);
 }


 関数 FetchRow($result)
 {
  $this->結果 = $結果;
  return @mysql_fetch_row($this->result);
 }


 関数 FetchArray($result)
 {
  $this->結果 = $結果;
  return @mysql_fetch_array($this->result, MYSQL_ASSOC);
 }
 関数 FetchArray2($result)
 {
  $this->結果 = $結果;
  return @mysql_fetch_array($this->result, MYSQL_BOTH);
 }
 

関数 FetchObject($result)
 {
  $this->結果 = $結果;
  return @mysql_fetch_object($this->result);
 }


 関数 FreeResult($result)
 {
  $this->結果 = $結果;
  return @mysql_free_result($this->result);
 }

関数 DataSeek($result)
 {
 //复位记录集指针
  $this->結果 = $結果;
  return mysql_data_seek($this->result,0);
 }
 
 関数 InsertID()
 {
  //$this->con = $con;
  return @mysql_insert_id($this->con);
 }


 関数Close()
 {
  if($this->con)
  {
   @mysql_close($this->con);
  }
 }
}

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/630886.html技術記事実践的な mysql 教程データベース接続クラス DB { //データベース接続 var $con = FALSE; function DB($MYSQL_HOST=MYSQL_HOST, $MYSQL_USER=MYSQL_USER, $MYSQL_PASS=MYSQL...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。