php実践_PHPチュートリアル5日目

WBOY
リリース: 2016-07-14 10:10:52
オリジナル
723 人が閲覧しました

私の理解では、php 単相構造パターンでは、クラス内に静的変数が 1 つだけ存在するように作成され、オブジェクトを返すメソッドを使用します。このメソッドは、オブジェクトを作成する前にオブジェクトが存在するかどうかを確認します。したがって、単一の目的を達成します。

new がこのクラスの意味であるように、__construct() を private に設定します。 「::」は静的メソッドを呼び出します

[php] /**
    *
   */
クラスマイクラス
{
静的プライベート $db_class
静的パブリック関数 getClass()
                                                            If (is_null(self::$db_class)) {
self::$db_class=new myclass(); 「オブジェクトの作成」
; }その他{
「元のオブジェクトに戻る」
; self::$db_class を返す
                                                                       }
プライベート関数 __construct()
                                                            エコー「11111111111111」 }

パブリック関数 __destruct(){
エコー「
ああああああああああ」; }
パブリック関数 show(){
「bbbbbbbbbbbbbb」をエコーし​​ます。 }
}
$a=myclass::getClass(); $a=myclass::getClass(); $a=myclass::getClass(); $a=myclass::getClass(); $a=myclass::getClass(); $a=myclass::getClass(); $a=myclass::getClass(); $a=myclass::getClass(); $a=myclass::getClass(); $a=myclass::getClass(); $a->show();

/*//new を直接使用すると、エラーが報告されます!!!
新しい myclass();
新しい myclass();

新しい myclass();
新しい myclass();

新しい myclass();
新しい myclass();
新しい myclass();
新しい myclass();*/
?>

/**
 *
 */
クラスマイクラス
{
静的プライベート $db_class;
静的パブリック関数 getClass()
{
If (is_null(self::$db_class)) {
self::$db_class=new myclass();
echo "オブジェクトの作成";
}その他{
echo "元のオブジェクトに戻る";
self::$db_class を返します;
}
}
プライベート関数 __construct()

{

エコー「11111111111111」;
}

パブリック関数 __destruct(){
echo "
aaaaaaaaaaaa";
}
パブリック関数 show(){
エコー「bbbbbbbbbbbbbb」;
}
}
$a=myclass::getClass();
$a=myclass::getClass();
$a=myclass::getClass();
$a=myclass::getClass();
$a=myclass::getClass();
$a=myclass::getClass();
$a=myclass::getClass();
$a=myclass::getClass();
$a=myclass::getClass();
$a=myclass::getClass();
$a->show();


/*//new を直接使用すると、エラーが報告されます!!!
新しい myclass();
新しい myclass();

新しい myclass();
新しい myclass();

新しい myclass();
新しい myclass();
新しい myclass();
新しい myclass();*/
?>

これは、単相性の 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 = '';
//静的インスタンス
静的プライベート $db_class
//このカテゴリを取得します
静的パブリック関数 getClass()
{
If (is_null(self::$db_class)) {
self::$db_class=new MySQL(); }
自己::$db_class を返す
}

//プライベートメソッドとして定義されている場合は、getClass を使用します
プライベート関数 __construct()
{
                                          }


パブリック関数 connect($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('設定エラー。'); 
        }
         
        $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=null){
        if (is_null($length)) {
            $this->query_list['limit']='limit '.$offset; 
            $this を返します。 
        }else {
            if(!isset($length)){
                $length = $offset; 
                $オフセット = 0; 
            }
                $this->query_list['limit'] = '制限 '.$offset.','.$length; 
                $this を返します。 
        }
 
    }
     
    パブリック関数データ($data){
        //读取データベース表字段、その後処理表单データベース
        $dataList = $this->getFields($this->query_list['table']); 
        $arr=配列(); 
        foreach ($dataList as $key=>$value) {
            if (array_key_exists ($key,$data) ) {
                $arr[$key]=$data[$key]; 
            }
             
        }
        //var_dump($arr);  
        /*
        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'] = $arr; 
        $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']):''; 
    // echo '----->'.$select_sql;  
        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,',').')'; 
 
    // echo 'add_sql'.$add_sql;  
        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 = '';

//静的インスタンス
静的プライベート $db_class;
//このカテゴリを取得します
静的パブリック関数 getClass()
{
If (is_null(self::$db_class)) {
self::$db_class=new MySQL();
}
return self::$db_class;
}

//プライベートメソッドとして定義されている場合は、getClass

を使用します。 プライベート関数 __construct()
{

}


    public function connect($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('設定エラー。');
        }
       
        $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=null){
  if (is_null($length)) {
   $this->query_list['limit']='limit '.$offset;
   $this を返します;
  }その他{
   if(!isset($length)){
    $length = $offset;
    $オフセット = 0;
   }
    $this->query_list['limit'] = '制限 '.$offset.','.$length;
    $this を返します;
  }

}
 
 パブリック関数データ($data){
  //データデータ表フィールドを读取し、その後処理表单データセット
  $dataList = $this->getFields($this->query_list['table']);
  $arr=array();
  foreach ($dataList as $key=>$value) {
   if (array_key_exists ($key,$data) ) {
    $arr[$key]=$data[$key];
   }
   
  }
  //var_dump($arr);
  /*
  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'] = $arr;
  $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']):'';
 // エコー '----->'.$select_sql;
  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,',').')';

// エコー 'add_sql'.$add_sql;
  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 `'

ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!