久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <bdo id='O8Ybv'></bdo><ul id='O8Ybv'></ul>
      <i id='O8Ybv'><tr id='O8Ybv'><dt id='O8Ybv'><q id='O8Ybv'><span id='O8Ybv'><b id='O8Ybv'><form id='O8Ybv'><ins id='O8Ybv'></ins><ul id='O8Ybv'></ul><sub id='O8Ybv'></sub></form><legend id='O8Ybv'></legend><bdo id='O8Ybv'><pre id='O8Ybv'><center id='O8Ybv'></center></pre></bdo></b><th id='O8Ybv'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='O8Ybv'><tfoot id='O8Ybv'></tfoot><dl id='O8Ybv'><fieldset id='O8Ybv'></fieldset></dl></div>

      <small id='O8Ybv'></small><noframes id='O8Ybv'>

      <tfoot id='O8Ybv'></tfoot>
      <legend id='O8Ybv'><style id='O8Ybv'><dir id='O8Ybv'><q id='O8Ybv'></q></dir></style></legend>

      1. 如何在 PHP 中選擇要與 PDO 一起使用的 MySQL 數(shù)據(jù)庫(kù)

        How do I select a MySQL database to use with PDO in PHP?(如何在 PHP 中選擇要與 PDO 一起使用的 MySQL 數(shù)據(jù)庫(kù)?)
      2. <legend id='VE59m'><style id='VE59m'><dir id='VE59m'><q id='VE59m'></q></dir></style></legend>

        <small id='VE59m'></small><noframes id='VE59m'>

          <bdo id='VE59m'></bdo><ul id='VE59m'></ul>
            <tfoot id='VE59m'></tfoot>
            <i id='VE59m'><tr id='VE59m'><dt id='VE59m'><q id='VE59m'><span id='VE59m'><b id='VE59m'><form id='VE59m'><ins id='VE59m'></ins><ul id='VE59m'></ul><sub id='VE59m'></sub></form><legend id='VE59m'></legend><bdo id='VE59m'><pre id='VE59m'><center id='VE59m'></center></pre></bdo></b><th id='VE59m'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VE59m'><tfoot id='VE59m'></tfoot><dl id='VE59m'><fieldset id='VE59m'></fieldset></dl></div>
              <tbody id='VE59m'></tbody>

                1. 本文介紹了如何在 PHP 中選擇要與 PDO 一起使用的 MySQL 數(shù)據(jù)庫(kù)?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我想在創(chuàng)建 PHP PDO 對(duì)象后選擇要使用的 MySQL 數(shù)據(jù)庫(kù).我該怎么做?

                  I want to select a MySQL database to use after a PHP PDO object has already been created. How do I do this?

                  // create PDO object and connect to MySQL
                  $dbh = new PDO( 'mysql:host=localhost;', 'name', 'pass' );
                  
                  // create a database named 'database_name'
                  
                  // select the database we just created ( this does not work )
                  $dbh->select_db( 'database_name' );
                  

                  是否有等效于 mysqli::select_db 的 PDO?

                  Is there a PDO equivalent to mysqli::select_db?

                  也許我試圖不正確地使用 PDO?請(qǐng)幫助或解釋.

                  Perhaps I'm trying to use PDO improperly? Please help or explain.

                  編輯

                  我不應(yīng)該使用 PDO 創(chuàng)建新數(shù)據(jù)庫(kù)嗎?我知道使用 PDO 的大部分好處在一個(gè)很少使用的操作中丟失了,它不會(huì)像 CREATE DATABASE 那樣插入數(shù)據(jù),但是不得不使用不同的連接來(lái)創(chuàng)建數(shù)據(jù)庫(kù)似乎很奇怪,然后創(chuàng)建 PDO 連接以進(jìn)行其他調(diào)用.

                  Should I not be using PDO to create new databases? I understand that the majority of benefits from using PDO are lost on a rarely used operation that does not insert data like CREATE DATABASE, but it seems strange to have to use a different connection to create the database, then create a PDO connection to make other calls.

                  推薦答案

                  通常,您會(huì)在連接時(shí)在 DSN 中指定數(shù)據(jù)庫(kù).但是,如果您正在創(chuàng)建一個(gè)新數(shù)據(jù)庫(kù),顯然您不能在創(chuàng)建之前將該數(shù)據(jù)庫(kù)指定為 DSN.

                  Typically you would specify the database in the DSN when you connect. But if you're creating a new database, obviously you can't specify that database the DSN before you create it.

                  您可以使用 USE 語(yǔ)句更改默認(rèn)數(shù)據(jù)庫(kù):

                  You can change your default database with the USE statement:

                  $dbh = new PDO("mysql:host=...;dbname=mysql", ...);
                  
                  $dbh->query("create database newdatabase");
                  
                  $dbh->query("use newdatabase");
                  

                  隨后的 CREATE TABLE 語(yǔ)句將在您的新數(shù)據(jù)庫(kù)中創(chuàng)建.

                  Subsequent CREATE TABLE statements will be created in your newdatabase.

                  來(lái)自@Mike 的重新評(píng)論:

                  Re comment from @Mike:

                  當(dāng)您像這樣切換數(shù)據(jù)庫(kù)時(shí),它似乎會(huì)強(qiáng)制 PDO 模擬準(zhǔn)備好的語(yǔ)句.將 PDO::ATTR_EMULATE_PREPARES 設(shè)置為 false,然后嘗試使用其他數(shù)據(jù)庫(kù)將失敗.

                  When you switch databases like that it appears to force PDO to emulate prepared statements. Setting PDO::ATTR_EMULATE_PREPARES to false and then trying to use another database will fail.

                  我只是做了一些測(cè)試,但我沒(méi)有看到這種情況發(fā)生.更改數(shù)據(jù)庫(kù)只發(fā)生在服務(wù)器上,它不會(huì)更改客戶端中 PDO 配置的任何內(nèi)容.舉個(gè)例子:

                  I just did some tests and I don't see that happening. Changing the database only happens on the server, and it does not change anything about PDO's configuration in the client. Here's an example:

                  <?php
                  
                  // connect to database
                  try {
                      $pdo = new PDO('mysql:host=huey;dbname=test', 'root', 'root');
                      $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                      $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
                  } catch(PDOException $err) {
                      die($err->getMessage());
                  }
                  
                  $stmt = $pdo->prepare("select * from foo WHERE i = :i");
                  $result = $stmt->execute(array("i"=>123));
                  print_r($stmt->fetchAll(PDO::FETCH_ASSOC));
                  
                  $pdo->exec("use test2");
                  
                  $stmt = $pdo->prepare("select * from foo2 WHERE i = :i AND i = :i");
                  $result = $stmt->execute(array("i"=>456));
                  print_r($stmt->fetchAll(PDO::FETCH_ASSOC));
                  

                  如果您說(shuō)的是真的,那么這應(yīng)該可以正常工作.僅當(dāng) PDO::ATTR_EMULATE_PREPARES 為真時(shí),PDO 才能多次使用給定的命名參數(shù).因此,如果您說(shuō)這個(gè)屬性設(shè)置為 true 作為更改數(shù)據(jù)庫(kù)的副作用,那么它應(yīng)該可以工作.

                  If what you're saying is true, then this should work without error. PDO can use a given named parameter more than once only if PDO::ATTR_EMULATE_PREPARES is true. So if you're saying that this attribute is set to true as a side effect of changing databases, then it should work.

                  但它不起作用——它得到一個(gè)錯(cuò)誤參數(shù)編號(hào)無(wú)效",表明非模擬的準(zhǔn)備好的語(yǔ)句仍然有效.

                  But it doesn't work -- it gets an error "Invalid parameter number" which indicates that non-emulated prepared statements remains in effect.

                  這篇關(guān)于如何在 PHP 中選擇要與 PDO 一起使用的 MySQL 數(shù)據(jù)庫(kù)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準(zhǔn)備好的語(yǔ)句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個(gè)服務(wù)器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無(wú)法識(shí)別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個(gè)參數(shù))
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結(jié)果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“l(fā)ocalhost的訪問(wèn)被拒絕)

                  <tfoot id='i9tCw'></tfoot>
                      <tbody id='i9tCw'></tbody>

                      <small id='i9tCw'></small><noframes id='i9tCw'>

                    1. <legend id='i9tCw'><style id='i9tCw'><dir id='i9tCw'><q id='i9tCw'></q></dir></style></legend>
                    2. <i id='i9tCw'><tr id='i9tCw'><dt id='i9tCw'><q id='i9tCw'><span id='i9tCw'><b id='i9tCw'><form id='i9tCw'><ins id='i9tCw'></ins><ul id='i9tCw'></ul><sub id='i9tCw'></sub></form><legend id='i9tCw'></legend><bdo id='i9tCw'><pre id='i9tCw'><center id='i9tCw'></center></pre></bdo></b><th id='i9tCw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='i9tCw'><tfoot id='i9tCw'></tfoot><dl id='i9tCw'><fieldset id='i9tCw'></fieldset></dl></div>

                          • <bdo id='i9tCw'></bdo><ul id='i9tCw'></ul>
                          • 主站蜘蛛池模板: 日韩免费福利视频 | 国产成人99久久亚洲综合精品 | 日韩成人一区 | 久久久久久毛片免费观看 | 免费在线黄色av | 亚洲香蕉在线视频 | 天堂精品 | 欧美成人a | 日日夜夜狠狠操 | 国产免费a视频 | 羞羞网站在线观看 | 国色天香成人网 | 美国黄色一级片 | 国产精品视频专区 | 国产精品呻吟久久av凹凸 | 欧美性a视频| a在线观看免费 | 日韩视频成人 | 欧美一二三区 | 欧美日韩在线视频一区二区 | 中文字幕在线剧情 | 亚洲成人免费视频在线 | 成人中文字幕在线观看 | 成人精品在线观看 | 国产影音先锋 | 久草热8精品视频在线观看 午夜伦4480yy私人影院 | 亚洲成人综合网站 | 男女爱爱网站 | 免费特级黄毛片 | 精品入口麻豆88视频 | 成人日韩 | 亚洲精品久久久久国产 | 美人の美乳で授乳プレイ | 亚洲国产成人精品女人久久久 | 国产乱精品一区二区三区 | 国产日韩欧美在线观看 | 国产精品久久久久一区二区三区 | 亚洲欧美中文日韩在线v日本 | 国产一区二区久久久 | 久久99视频 | 久久99精品久久久 |