<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                **1、什么是建造者模式?** ? ? ? 建造者設計模式定義了處理其他對象的復雜構建的對象設計。 **2、用一個簡單的mysql,mongo鏈接類說明:** ~~~ <?php /** * 數據庫鏈接類 - 此類只是一個簡單的說明實例,如需使用,請加以簡單完善修改后在使用 * ------------------------ * @author liuxinming * @Dtime:2012-07-02 */ class connect{ private $localhost;//主機 sql服務器 private $dbuser;//數據庫用戶名 private $password;//數據庫密碼 private $database;//數據庫名 private $charset;//編碼 private $pconnect;//是否持久鏈接 private $port; //數據庫端口 private $mongo;//mongo 對象 private $db;//db mongodb對象數據庫 public function __construct($config){ $this->localhost=$config['localhost']; $this->dbuser=$config['dbuser']; $this->password=$config['password']; $this->database=$config['database']; $config['charset']?$this->charset=$config['charset']:'utf8';//默認為utf8字符集 $config['pconnect']?$this->pconnect=$config['pconnect']:0;//默認為utf8字符集 $config['port']?$this->port=$config['port']:3360;//端口 //MongoDB if (!$config['option']) $config['option'] = array('connect' => true); } /** * MYSQL連接 * @return obj */ public function db_connect(){ $conn = ($config['pconnect'] == 0) ? mysql_connect($this->localhost, $this->dbuser, $this->password, true) : mysql_pconnect($this->localhost, $this->dbuser, $this->password); if(!$conn){ die('Could not connect: ' . mysql_error()); } mysql_query('SET NAMES ' . $this->database, $conn); //設置數據庫字符集 $dbname=@mysql_select_db($this->database, $conn); if(!$dbname){ die ("Can\'t use test_db : " . mysql_error()); } return $conn; } /** * NoSql mongoDB鏈接 */ public function mongodb(){ $server = 'mongodb://' . $this->localhost . ':' . $this->port; //鏈接mongodb 數據庫 $this->mongo = new Mongo($server, $this->options); //選擇數據庫 $this->db = $this->mongo->selectDB($this->database); //用戶名 密碼 $this->db->authenticate($this->dbuser, $this->password); //$mongo->connect(); //調用connect方法,來保持連接。 //$mongo->close(); //調用close方法,關閉數據庫連接。 //$alldb= $this->mongo->listDBs(); //調用listDBs方法,返回$alldb這個多維數組。顯示所有的數據庫。 } } /** * 建造者模式類 目的是處理數據庫鏈接對象的復雜構建的對象設計 * 這只是一個簡單說明類,如需分裝一個完整的正式環境下用的數據庫多種類型鏈接類,請稍微加以修改即可用。 * 當然此類你也可以直接拿去用,只是感覺不完美。 */ class MysqlDb{ protected $obj; protected $sqltype; public function __construct($config){ $this->obj=new connect($config); $this->sqltype=$config['sqltype']; } public function buildDb(){ if($this->sqltype=='mysql'){ $this->obj->db_connect(); }else{ $this->obj->mongodb(); } } } /* 創建過程被封裝了,方便切換使用mysql 或 mongo數據庫鏈接 */ $config = array( 'sqltype'=>'mysql', 'localhost' => '127.0.0.1', 'dbuser' => 'root', 'password' => '123456' , 'database'=>'weike', ); $sql=new MysqlDb($config); $sql->buildDb(); // 用sql查詢測試 $sql='select * from pre_brand'; $result =mysql_query($sql); $row=mysql_fetch_array($result); print_r($row); mysql_free_result($result);//釋放與之關聯的資源 (腳本執行完畢后會自動釋放內存) ?> ~~~ 測試輸出結果: ~~~ Array ( [0] => 1 [bid] => 1 [1] => 9 [uid] => 9 [2] => 0 [like] => 0 [3] => [type] => [4] => 0 [local] => 0 [5] => 0 [date] => 0 [6] => 0 [extra1] => 0 [7] => 0 [extra2] => 0 [8] => 0 [extra3] => 0 [9] => 0 [extra4] => 0 [10] => 0.00 [extra5] => 0.00 [11] => 0.00 [extra6] => 0.00 [12] => 0.00 [extra7] => 0.00 [13] => 0.00 [extra8] => 0.00 ) ~~~ PS:由于我的ubuntu服務器沒有裝MongoDB,所有沒有測試mongodb。有安裝的同志可以測試下。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看