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

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

Jul 14, 2016 am 10:10 AM
php 説明書 作成する 変数 実戦 理解する デザインパターン 行為 静的

私の理解では、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 `'

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

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

CakePHP プロジェクトの構成 CakePHP プロジェクトの構成 Sep 10, 2024 pm 05:25 PM

この章では、CakePHP の環境変数、一般設定、データベース設定、電子メール設定について理解します。

Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Dec 24, 2024 pm 04:42 PM

PHP 8.4 では、いくつかの新機能、セキュリティの改善、パフォーマンスの改善が行われ、かなりの量の機能の非推奨と削除が行われています。 このガイドでは、Ubuntu、Debian、またはその派生版に PHP 8.4 をインストールする方法、または PHP 8.4 にアップグレードする方法について説明します。

CakePHP の日付と時刻 CakePHP の日付と時刻 Sep 10, 2024 pm 05:27 PM

Cakephp4 で日付と時刻を操作するには、利用可能な FrozenTime クラスを利用します。

CakePHP ファイルのアップロード CakePHP ファイルのアップロード Sep 10, 2024 pm 05:27 PM

ファイルのアップロードを行うには、フォーム ヘルパーを使用します。ここではファイルアップロードの例を示します。

CakePHP ルーティング CakePHP ルーティング Sep 10, 2024 pm 05:25 PM

この章では、ルーティングに関連する次のトピックを学習します。

CakePHP について話し合う CakePHP について話し合う Sep 10, 2024 pm 05:28 PM

CakePHP は、PHP 用のオープンソース フレームワークです。これは、アプリケーションの開発、展開、保守をより簡単にすることを目的としています。 CakePHP は、強力かつ理解しやすい MVC のようなアーキテクチャに基づいています。モデル、ビュー、コントローラー

PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 Dec 20, 2024 am 11:31 AM

Visual Studio Code (VS Code とも呼ばれる) は、すべての主要なオペレーティング システムで利用できる無料のソース コード エディター (統合開発環境 (IDE)) です。 多くのプログラミング言語の拡張機能の大規模なコレクションを備えた VS Code は、

CakePHP バリデータの作成 CakePHP バリデータの作成 Sep 10, 2024 pm 05:26 PM

Validator は、コントローラーに次の 2 行を追加することで作成できます。

See all articles