ホームページ  >  記事  >  バックエンド開発  >  PHP実践1日目_PHPチュートリアル

PHP実践1日目_PHPチュートリアル

WBOY
WBOYオリジナル
2016-07-14 10:11:03704ブラウズ

今日は何かを学びました

エンコーディングを設定するためにphpがブラウザに送信されます

header('content-type:text/html;charset=utf-8');


Smarty テンプレート エンジンは、クラス内の N 個の複数のエラーを報告します


brophpのDBクラスを修正したら単独では使えなくなりました


thinkphpのDBクラスは修正しても単体では使えません


最後に、オンラインのオープンソースの mysql クラスを使用しました


[php] // +---------------------------------------------- --- ----------------------------------
// |MySQL 操作クラス
// +---------------------------------------------- --- ----------------------------------
// |@微冰QQ:496928838
// +---------------------------------------------- --- ----------------------------------
クラス MySQL{

プライベート $db_mysql_hostname
プライベート $db_mysql_username
プライベート $db_mysql_password
プライベート $db_mysql_database
プライベート $db_mysql_port
プライベート $db_mysql_charset

プライベート $query_list = array();
//クエリ数
パブリック $query_count = 0; //クエリ開始時刻
公開 $query_start_time

//現在のクエリID
保護された $クエリ ID
//現在の接続
保護された $conn
// トランザクション命令の数
保護された $transTimes = 0; // レコード数を返すか、レコード数に影響を与える
保護された $numRows = 0; // エラーメッセージ
保護された $error = '';
パブリック関数 __construct($hostname_or_conf,$username,$password,$database,$port = '3306',$char = 'utf8'){
If(is_array($hostname_or_conf)){
$this->db_mysql_hostname = $hostname_or_conf['hostname']; $this->db_mysql_username = $hostname_or_conf['username']; $this->db_mysql_password = $hostname_or_conf['パスワード']; $this->db_mysql_database = $hostname_or_conf['database']; $this->db_mysql_port = isset($hostname_or_conf['port'])?$hostname_or_conf['port']:'3306'; $this->db_mysql_charset = isset($hostname_or_conf['charset'])?$hostname_or_conf['charset']:'utf8';                                           }elseif(!empty($hostname_or_conf)||!empty($username)||!empty($password)||!empty($database))
                                                            $this->db_mysql_hostname = $hostname_or_conf; $this->db_mysql_username = $username; $this->db_mysql_password = $password; $this->db_mysql_database = $database; $this->db_mysql_port = $port; $this->db_mysql_charset = $char;                                             }その他{
die('設定エラー。'); }
$this->connect(); }

プライベート関数 connect(){
$server = $this->db_mysql_hostname.':'.$this->db_mysql_port;        $this->conn = mysql_connect($server,$this->db_mysql_username,$this->db_mysql_password,true) または die('MySQL DB 接続エラー!'); 
        mysql_select_db($this->db_mysql_database,$this->conn) または die('select db error!'); 
        mysql_query("セット名 " . $this->db_mysql_charset, $this->conn); 
    }
    /**
+------------------------------------------------ ----------
*データオブジェクトの値を設定します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
*テーブル、場所、順序、制限、データ、フィールド、結合、グループ、所有
+------------------------------------------------ ----------
​​*/
    パブリック関数テーブル($table){
        $this->query_list['table'] = $table; 
        $this を返します。 
    }
     
    パブリック関数 where($where){
        $this->query_list['where'] = $where; 
        $this を返します。 
    }
     
    公共機能注文($order){
        $this->query_list['order'] = $order; 
        $this を返します。 
    }
     
    パブリック関数の制限($offset,$length){
        if(!isset($length)){
            $length = $offset; 
            $オフセット = 0; 
        }
        $this->query_list['limit'] = '制限 '.$offset.','.$length; 
        $this を返します。 
    }
     
    パブリック関数データ($data){
        /*
        if(is_object($data)){
            $data = get_object_vars($data);
        }elseif (is_string($data)){
            parse_str($data,$data);
        }elseif(!is_array($data)){
            //ログ:DATA_TYPE_INVALID
        }
        */
        $this->query_list['data'] = $data; 
        $this を返します。 
    }
    パブリック関数フィールド($fields){
        $this->query_list['fields'] = $fields; 
        $this を返します。 
    }
    パブリック関数結合($join){
        $this->query_list['join'] = $join; 
        $this を返します。 
    }
    パブリック関数グループ($group){
        $this->query_list['group'] = $group; 
        $this を返します。 
    }
    パブリック関数 have($having){
        $this->query_list['having'] = $having; 
        $this を返します。 
    }
    /**
     +------------------------------------------------ --------
     * 查询
     +------------------------------------------------ --------
     * @アクセス公開
     +------------------------------------------------ --------
     * @param
     +------------------------------------------------ --------
     */
    パブリック関数 select(){
        $select_sql = '選択'; 
        $fields = isset($this->query_list['fields'])?$this->query_list['fields']:'*'; 
        $select_sql.=$fields; 
        $select_sql.= ' from `'.$this->query_list['table'].'` '; 
         
        isset($this->query_list['join'])?($select_sql.=$this->query_list['join']):''; 
        isset($this->query_list['where'])?($select_sql.=' where '.$this->query_list['where']):''; 
        isset($this->query_list['group'])?($select_sql.=' group by'.$this->query_list['group']):''; 
        isset($this->query_list['having'])?($select_sql.=' mysql を持つ '.$this->query_list['having']):''; 
        isset($this->query_list['order'])?($select_sql.=' order by '.$this->query_list['order']):''; 
        isset($this->query_list['limit'])?($select_sql.=' '.$this->query_list['limit']):''; 
         
        return $this->query($select_sql); 
    }
    /**
+------------------------------------------------ ----------
*
を追加 +------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
    パブリック関数 add(){
        $add_sql = '`'.$this->query_list['table'] に挿入します。'` (';
         
        $data = $this->query_list['data']; 
        $値 = $フィールド = ''; 
        foreach($data as $k=>$v){
            $field .= '`'.$k.'`,'; 
            if(is_numeric($v))
                $value .= $v.','; 
            その他
                $value .= '''.$v.'','; 
        }
        $add_sql .= rtrim($field,',').') 値 ('.rtrim($value,',').')'; 
 
        return $this->execute($add_sql); 
    }
    /**
+------------------------------------------------ ----------
*削除
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
    パブリック関数 delete(){
        $del_sql = '`.$this->query_list['table'].'` から削除します。where '.$this->query_list['where']; 
         
        if(isset($this->query_list['order']))
            $del_sql .= 'order by '.$this->query_list['order']; 
        if(isset($this->query_list['limit']))
            $del_sql .= ' '.$this->query_list['limit']; 
             
        return $this->execute($del_sql); 
         
    }
    /**
+------------------------------------------------ ----------
*更新
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
    パブリック関数 update(){
        $update_sql = 'update `'.$this->query_list['table'].'` set '; 
        $data = $this->query_list['data']; 
         
        foreach($data as $k=>$v){
            if(is_numeric($v))
                $update_sql .= '`'.$k.'` ='.$v.','; 
            その他
                $update_sql .= ''.$k.'' =''.$v.'','; 
        }
        $update_sql = rtrim($update_sql,','); 
        if(isset($this->query_list['where']))
            $update_sql .= ' where '.$this->query_list['where']; 
        if(isset($this->query_list['order']))
            $update_sql .= ' order by '.$this->query_list['order']; 
        if(isset($this->query_list['limit']))
            $update_sql .= ' '.$this->query_list['limit']; 
         
        return $this->execute($update_sql); 
         
    }
     /**
+------------------------------------------------ ----------
* クエリを実行してデータセットを返します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param string $sql SQLコマンド
​​*/
    パブリック関数クエリ($sql) {
        if ( !$this->conn ) は false を返します。 
        $this->queryStr = $sql; 
        //释放前回の查询結果
        if ( $this->queryID ) { $this->free();    }
         
        $this->query_start_time = microtime(true); 
         
        $this->queryID = mysql_query($sql, $this->conn); 
        $this->query_count++; 
        if ( false === $this->クエリID ) {
            $this->error(); 
            false を返します。 
        } その他 {
            $this->numRows = mysql_num_rows($this->queryID); 
            $this->getAll(); を返す 
        }
    }
    /**
+------------------------------------------------ ----------
* ステートメントを実行します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param string $sql SQLコマンド
+------------------------------------------------ ----------
​​*/
    パブリック関数実行($sql) {
        if ( !$this->conn ) は false を返します。 
        $this->queryStr = $sql; 
        //释放前回の查询結果
        if ( $this->queryID ) { $this->free();    }
         
        $this->query_start_time = microtime(true); 
         
        $result = mysql_query($sql, $this->conn) ; 
        $this->query_count++; 
        if ( false === $result) {
            $this->error(); 
            false を返します。 
        } その他 {
            $this->numRows = mysql_affected_rows($this->conn); 
            $this->numRows を返します; 
        }
    }
    /**
+------------------------------------------------ ----------
* すべてのクエリデータを取得します
+------------------------------------------------ ----------
* @アクセス非公開
+------------------------------------------------ ----------
* @return 配列
​​*/
    プライベート関数 getAll() {
        // 返される回数データ集
        $result = 配列(); 
        if($this->numRows>0) {
            while($row = mysql_fetch_assoc($this->クエリID)){
                $result[] = $row; 
            }
            mysql_data_seek($this->クエリID,0); 
        }
        $result を返します。 
    }
    /**
     +------------------------------------------------ --------
     * データテーブルの文字列情報を取得します
     +------------------------------------------------ --------
     * @アクセス公開
     +------------------------------------------------ --------
     */
    パブリック関数 getFields($tableName) {
        $result = $this->query('SHOW COLUMNS FROM `'.$tableName.'`'); 
        $info = 配列(); 
        if($result) {
            foreach ($result as $key => $val) {
                $info[$val['フィールド']] = array(
                    「名前」 => $val['フィールド']、
                    「タイプ」 => $val['タイプ'],
                    'notnull' => (bool) ($val['Null'] === ''), // null でない場合は空、null ははい
                    'デフォルト' => $val['デフォルト']、
                    'プライマリ' => (strto lower($val['Key']) == 'pri'),
                    'autoinc' => (strto lower($val['Extra']) == 'auto_increment'),
                ); 
            }
        }
        $info を返します。 
    }
    /**
+------------------------------------------------ ----------
* データベースのテーブル情報を取得します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
​​*/
    パブリック関数 getTables($dbName='') {
        if(!empty($dbName)) {
           $sql = '.$dbName からのテーブルを表示; 
        }その他{
           $sql = 'テーブルを表示 '; 
        }
        $result = $this->query($sql); 
        $info = 配列(); 
        foreach ($result as $key => $val) {
            $info[$key] = 現在($val); 
        }
        $info を返します。 
    }
 
    /**
+------------------------------------------------ ----------
* 最後の操作のID
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
     パブリック関数 last_insert_id(){
        return mysql_insert_id($this->conn); 
    }
    /**
* 結果セット数を指定して
を実行する ​​*/
    パブリック関数カウント($sql){
        return $this->execute($sql); 
    }
    /**
+------------------------------------------------ ----------
* 取引を開始します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @return void
+------------------------------------------------ ----------
​​*/
    パブリック関数 startTrans() {
        if ($this->transTimes == 0) {
            mysql_query('トランザクションの開始', $this->conn); 
        }
        $this->transTimes++; 
        戻る ; 
    }
 
    /**
+------------------------------------------------ ----------
* トランザクションを送信します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @return boolen
+------------------------------------------------ ----------
​​*/
    パブリック関数 commit()
    {
        if ($this->transTimes > 0) {
            $result = mysql_query('COMMIT', $this->conn); 
            $this->transTimes = 0; 
            if(!$result){
                throw new Exception($this->error()); 
            }
        }
        true を返します。 
    }
 
    /**
+------------------------------------------------ ----------
* トランザクションのロールバック
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @return boolen
+------------------------------------------------ ----------
​​*/
    パブリック関数 rollback()
    {
        if ($this->transTimes > 0) {
            $result = mysql_query('ROLLBACK', $this->conn); 
            $this->transTimes = 0; 
            if(!$result){
                throw new Exception($this->error()); 
            }
        }
        true を返します。 
    }
    /**
+------------------------------------------------ ----------
* エラーメッセージ
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
     パブリック関数 error() {
        $this->error = mysql_error($this->conn); 
        if('' != $this->queryStr){
            $this->error .= "n [ SQL语句 ] : ".$this->queryStr; 
        }
        $this->エラーを返します; 
    }
    /**
+------------------------------------------------ ----------
* クエリ結果をリリース
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
​​*/
    public function free() {
        @mysql_free_result($this->クエリID); 
        $this->クエリID = 0; 
        $this->query_list = null; 
    }
    /**
+------------------------------------------------ ----------
*接続を閉じる
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
    関数 close(){
        if ($this->conn && !mysql_close($this->conn)){
            throw new Exception($this->error()); 
        }
        $this->conn = 0; 
        $this->クエリカウント = 0; 
    }
    /**
+------------------------------------------------ ----------
*破壊方法
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
​​*/
    関数 __destruct(){
         $this->close(); 
    }
}

// +---------------------------------------------- --- ----------------------------------
// |MySQL 操作クラス
// +---------------------------------------------- --- ----------------------------------
// |@微梁QQ:496928838
// +---------------------------------------------- --- ----------------------------------
クラスMySQL{

プライベート $db_mysql_hostname;
プライベート $db_mysql_username;
プライベート $db_mysql_password;
プライベート $db_mysql_database;
プライベート $db_mysql_port;
プライベート $db_mysql_charset;

プライベート $query_list = array();

//クエリ数
パブリック $query_count = 0;
//クエリ開始時刻
public $query_start_time;

//現在のクエリID
保護された $queryID;
//現在の接続
保護された $conn;
//トランザクション命令の数
保護された $transTimes = 0;
//レコード数を返すか、レコード数に影響を与えます
保護された $numRows = 0;
// エラーメッセージ
protected $error = '';

パブリック関数 __construct($hostname_or_conf,$username,$password,$database,$port = '3306',$char = 'utf8'){
if(is_array($hostname_or_conf)){
$this->db_mysql_hostname = $hostname_or_conf['hostname'];
$this->db_mysql_username = $hostname_or_conf['username'];
$this->db_mysql_password = $hostname_or_conf['パスワード'];
$this->db_mysql_database = $hostname_or_conf['データベース'];
$this->db_mysql_port = isset($hostname_or_conf['port'])?$hostname_or_conf['port']:'3306';
$this->db_mysql_charset = isset($hostname_or_conf['charset'])?$hostname_or_conf['charset']:'utf8';

}elseif(!empty($hostname_or_conf)||!empty($username)||!empty($password)||!empty($database))
{
$this->db_mysql_hostname = $hostname_or_conf;
$this->db_mysql_username = $username;
$this->db_mysql_password = $password;
$this->db_mysql_database = $database;
$this->db_mysql_port = $port;
$this->db_mysql_charset = $char;

}その他{
Die('設定エラー。');
}
$this->connect();
}

プライベート関数 connect(){
$server = $this->db_mysql_hostname.':'.$this->db_mysql_port;
$this->conn = mysql_connect($server,$this->db_mysql_username,$this->db_mysql_password,true) または die('MySQL DB 接続エラー!');
mysql_select_db($this->db_mysql_database,$this->conn) または die('select db error!');
mysql_query("セット名 " . $this->db_mysql_charset, $this->conn);
}
/**
+------------------------------------------------ ----------
* データオブジェクトの値を設定します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
*テーブル、場所、順序、制限、データ、フィールド、結合、グループ、所有
+------------------------------------------------ ----------
​​*/
パブリック関数テーブル($table){
$this->query_list['table'] = $table;
$this を返します;
}

パブリック関数 where($where){
$this->query_list['where'] = $where;
$this を返します;
}

パブリック関数の順序($order){
$this->query_list['order'] = $order;
$this を返します;
}

パブリック関数の制限($offset,$length){
if(!isset($length)){
$length = $offset;
$オフセット = 0;
}
$this->query_list['limit'] = '制限 '.$offset.','.$length;
$this を返します;
}

 パブリック関数データ($data){
  /*
  if(is_object($data)){
   $data = get_object_vars($data);
  }elseif (is_string($data)){
   parse_str($data,$data);
  }elseif(!is_array($data)){
   //ログ:DATA_TYPE_INVALID
  }
  */
  $this->query_list['data'] = $data;
  $this を返します;
 }
 パブリック関数フィールド($fields){
  $this->query_list['fields'] = $fields;
  $this を返します;
 }
 パブリック関数 join($join){
  $this->query_list['join'] = $join;
  $this を返します;
 }
 パブリック関数グループ($group){
  $this->query_list['group'] = $group;
  $this を返します;
 }
 パブリック関数having($having){
  $this->query_list['having'] = $having;
  $this を返します;
 }
 /**
+------------------------------------------------ ----------
* クエリ
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
 パブリック関数 select(){
  $select_sql = '選択';
  $fields = isset($this->query_list['fields'])?$this->query_list['fields']:'*';
  $select_sql.=$fields;
  $select_sql.= ' from `'.$this->query_list['table'].'` ';
  
  isset($this->query_list['join'])?($select_sql.=$this->query_list['join']):'';
  isset($this->query_list['where'])?($select_sql.=' where '.$this->query_list['where']):'';
  isset($this->query_list['group'])?($select_sql.=' group by'.$this->query_list['group']):'';
  isset($this->query_list['having'])?($select_sql.=' mysql を持つ '.$this->query_list['having']):'';
  isset($this->query_list['order'])?($select_sql.=' order by '.$this->query_list['order']):'';
  isset($this->query_list['limit'])?($select_sql.=' '.$this->query_list['limit']):'';
  
  return $this->query($select_sql);
 }
 /**
+------------------------------------------------ ----------
*
を追加 +------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
 パブリック関数 add(){
  $add_sql = '`' に挿入します。$this->query_list['table'].'` (';
  
  $data = $this->query_list['data'];
  $value = $field = '';
  foreach($data as $k=>$v){
   $field .= '`'.$k.'`,';
   if(is_numeric($v))
    $value .= $v.',';
   それ以外
    $value .= '''.$v.'',';
  }
  $add_sql .= rtrim($field,',').') 値 ('.rtrim($value,',').')';

return $this->execute($add_sql);
 }
 /**
+------------------------------------------------ ----------
*削除
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
 パブリック関数 delete(){
  $del_sql = '「.$this->query_list['table'].'` から削除します。」 where '.$this->query_list['where'];
  
  if(isset($this->query_list['order']))
   $del_sql .= 'order by '.$this->query_list['order'];
  if(isset($this->query_list['limit']))
   $del_sql .= ' '.$this->query_list['limit'];
   
  return $this->execute($del_sql);
  
 }
 /**
+------------------------------------------------ ----------
*更新
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
 パブリック関数 update(){
  $update_sql = '更新 `'.$this->query_list['テーブル'].'` セット ';
  $data = $this->query_list['data'];
  
  foreach($data as $k=>$v){
   if(is_numeric($v))
    $update_sql .= '`'.$k.'` ='.$v.',';
   それ以外
    $update_sql .= ''.$k.'' =''.$v.'',';
  }
  $update_sql = rtrim($update_sql,',');
  if(isset($this->query_list['where']))
   $update_sql .= ' where '.$this->query_list['where'];
  if(isset($this->query_list['order']))
   $update_sql .= ' order by '.$this->query_list['order'];
  if(isset($this->query_list['limit']))
   $update_sql .= ' '.$this->query_list['limit'];
  
  return $this->execute($update_sql);
  
 }
  /**
+------------------------------------------------ ----------
* クエリを実行してデータセットを返します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param string $sql SQLコマンド
​​*/
    パブリック関数クエリ($sql) {
        if ( !$this->conn ) が false を返す;
        $this->queryStr = $sql;
        //释放前回の查询結果
        if ( $this->queryID ) { $this->free();    }
       
        $this->query_start_time = microtime(true);
       
        $this->queryID = mysql_query($sql, $this->conn);
        $this->query_count++;
        if ( false === $this->クエリID ) {
            $this->error();
            false を返します;
        } その他 {
            $this->numRows = mysql_num_rows($this->クエリID);
            $this->getAll();
を返す        }
    }
 /**
+------------------------------------------------ ----------
* ステートメントを実行します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param string $sql SQLコマンド
+------------------------------------------------ ----------
​​*/
    パブリック関数実行($sql) {
        if ( !$this->conn ) が false を返す;
        $this->queryStr = $sql;
        //释放前回の查询結果
        if ( $this->queryID ) { $this->free();    }
       
        $this->query_start_time = microtime(true);
       
        $result = mysql_query($sql, $this->conn) ;
        $this->query_count++;
        if ( false === $result) {
            $this->error();
            false を返します;
        } その他 {
            $this->numRows = mysql_affected_rows($this->conn);
            $this->numRows を返す;
        }
    }
 /**
+------------------------------------------------ ----------
* すべてのクエリデータを取得します
+------------------------------------------------ ----------
* @アクセス非公開
+------------------------------------------------ ----------
* @return 配列
​​*/
    プライベート関数 getAll() {
        // 返される回数データ集
        $result = array();
        if($this->numRows>0) {
            while($row = mysql_fetch_assoc($this->クエリID)){
                $result[] = $row;
            }
            mysql_data_seek($this->クエリID,0);
        }
        $result を返します;
    }
 /**
+------------------------------------------------ ----------
* データテーブルのフィールド情報を取得します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
​​*/
    パブリック関数 getFields($tableName) {
        $result = $this->query('SHOW COLUMNS FROM `'.$tableName.'`');
        $info = array();
        if($result) {
            foreach ($result as $key => $val) {
                $info[$val['フィールド']] = array(
                    「名前」 => $val['フィールド'],
                    「タイプ」 => $val['タイプ'],
                    'notnull' => (bool) ($val['Null'] === ''), // null でない場合は空、null は Yes です
                    'デフォルト' => $val['デフォルト'],
                    'プライマリ' => (strto lower($val['Key']) == 'pri'),
                    'autoinc' => (strto lower($val['Extra']) == 'auto_increment'),
                );
            }
        }
        $info を返します;
    }
 /**
+------------------------------------------------ ----------
* データベースのテーブル情報を取得します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
​​*/
    パブリック関数 getTables($dbName='') {
        if(!empty($dbName)) {
           $sql = '.$dbName からテーブルを表示;
        }その他{
           $sql = 'テーブルを表示';
        }
        $result = $this->query($sql);
        $info = array();
        foreach ($result as $key => $val) {
            $info[$key] = 現在($val);
        }
        $info を返します;
    }

/**
+------------------------------------------------ ----------
* 最後の操作のID
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
  パブリック関数 last_insert_id(){
        return mysql_insert_id($this->conn);
    }
    /**
* 結果セット数を指定して
を実行する ​​*/
    パブリック関数カウント($sql){
        return $this->execute($sql);
    }
 /**
+------------------------------------------------ ----------
* 取引を開始します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @return void
+------------------------------------------------ ----------
​​*/
    パブリック関数 startTrans() {
        if ($this->transTimes == 0) {
            mysql_query('トランザクションの開始', $this->conn);
        }
        $this->transTimes++;
        戻ります;
    }

/**
+------------------------------------------------ ----------
* トランザクションを送信します
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @return boolen
+------------------------------------------------ ----------
​​*/
    パブリック関数 commit()
    {
        if ($this->transTimes > 0) {
            $result = mysql_query('COMMIT', $this->conn);
            $this->transTimes = 0;
            if(!$result){
                新しい例外をスロー($this->error());
            }
        }
        true を返します;
    }

/**
+------------------------------------------------ ----------
* トランザクションのロールバック
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @return boolen
+------------------------------------------------ ----------
​​*/
    パブリック関数 rollback()
    {
        if ($this->transTimes > 0) {
            $result = mysql_query('ROLLBACK', $this->conn);
            $this->transTimes = 0;
            if(!$result){
                新しい例外をスロー($this->error());
            }
        }
        true を返します;
    }
 /**
+------------------------------------------------ ----------
* エラーメッセージ
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
* @param
+------------------------------------------------ ----------
​​*/
  パブリック関数 error() {
        $this->error = mysql_error($this->conn);
        if('' != $this->queryStr){
            $this->error .= "n [ SQL语句 ] : ".$this->queryStr;
        }
        $this->エラーを返す;
    }
 /**
+------------------------------------------------ ----------
* クエリ結果をリリース
+------------------------------------------------ ----------
* @アクセス公開
+------------------------------------------------ ----------
​​*/
    パブリック関数 free() {
        @mysql_free_result($this->クエリID);
        $this->クエリID = 0;
        $this->query_list = null;
    }
    /**

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。