<legend id='VitIt'><style id='VitIt'><dir id='VitIt'><q id='VitIt'></q></dir></style></legend>
  • <tfoot id='VitIt'></tfoot>

      <bdo id='VitIt'></bdo><ul id='VitIt'></ul>

    1. <small id='VitIt'></small><noframes id='VitIt'>

      1. <i id='VitIt'><tr id='VitIt'><dt id='VitIt'><q id='VitIt'><span id='VitIt'><b id='VitIt'><form id='VitIt'><ins id='VitIt'></ins><ul id='VitIt'></ul><sub id='VitIt'></sub></form><legend id='VitIt'></legend><bdo id='VitIt'><pre id='VitIt'><center id='VitIt'></center></pre></bdo></b><th id='VitIt'></th></span></q></dt></tr></i><div id='VitIt'><tfoot id='VitIt'></tfoot><dl id='VitIt'><fieldset id='VitIt'></fieldset></dl></div>

        使用 MySQLi 连接到多个数据库

        时间:2023-07-29

              <tbody id='1YQrN'></tbody>
            • <bdo id='1YQrN'></bdo><ul id='1YQrN'></ul>

              1. <legend id='1YQrN'><style id='1YQrN'><dir id='1YQrN'><q id='1YQrN'></q></dir></style></legend>
                  <i id='1YQrN'><tr id='1YQrN'><dt id='1YQrN'><q id='1YQrN'><span id='1YQrN'><b id='1YQrN'><form id='1YQrN'><ins id='1YQrN'></ins><ul id='1YQrN'></ul><sub id='1YQrN'></sub></form><legend id='1YQrN'></legend><bdo id='1YQrN'><pre id='1YQrN'><center id='1YQrN'></center></pre></bdo></b><th id='1YQrN'></th></span></q></dt></tr></i><div id='1YQrN'><tfoot id='1YQrN'></tfoot><dl id='1YQrN'><fieldset id='1YQrN'></fieldset></dl></div>
                • <small id='1YQrN'></small><noframes id='1YQrN'>

                • <tfoot id='1YQrN'></tfoot>

                  本文介绍了使用 MySQLi 连接到多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我需要使用 PHP 连接到两个数据库,并使用第一个查询的结果从第二个数据库中获取我需要的其余数据.

                  I need to connect to two databases using PHP and use the results from the first query to get the rest of the data I need out of a second database.

                  因此,对于第二个连接,我需要连接到第二个数据库并选择状态和邮政编码,其中连接 1(客户端)的结果等于数据库 2 中的名字.我该怎么做?

                  So for the second connection, I need to connect to the second database and Select state and zipcode where the results from connection 1 (client) is equal to the firstname in database 2. How would I do this?

                  <?php
                  // check if the 'id' variable is set in URL, and check that it is valid
                  if (isset($_GET['cd']) && is_numeric($_GET['cd'])) {
                  
                      // get id value
                      $id = intval($_GET['cd']);
                  }
                  
                  $results = $id;
                  //Open a new connection to the MySQL server
                  require "calendarconnect.php";
                  
                  //chained PHP functions
                  $client = $mysqli->query("SELECT client FROM appointments WHERE ID = $results")->fetch_object()->client;
                  print  $client; //output value
                  
                  $mysqli->close();
                  

                  连接到数据库代码类似于下面

                  Connection To Database Code is similar to the below

                  <?php
                  //Open a new connection to the MySQL server
                  $mysqli = new mysqli('localhost','some database','some password','some username');
                  
                  //Output any connection error
                  if ($mysqli->connect_error) {
                      die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
                  }
                  

                  推荐答案

                  这没有经过测试,但我认为它会像这样.

                  This isn't tested, but I think it would go something like this.

                  <?php
                  
                  $dbc1 = new MySQLi()or die('error connecting to database');
                  $dbc2 = new MySQLi()or die('error connecting to database');
                  
                  
                  
                  //build query 1
                  $query1 = "SELECT * FROM Table";
                  
                  $result1 = $dbc1->query($query) or die("Error in query");
                  $thing1 = '';
                  // check result
                  if($result1->num_rows){
                      //fetch result as object
                      $row = $result1->fetch_object();
                  
                      //set attributes
                      $thing1 = $row->Name;
                  }   
                  
                  
                  //build query 2
                  $query2 = "SELECT * FROM AnotherTable WHERE Id = '$thing1'";
                  
                  $result2 = $dbc2->query($query) or die("Error in query");
                  $thing2 = '';
                  // check result
                  if($result2->num_rows){
                      //fetch result as object
                      $row = $result2->fetch_object();
                  
                      //set attributes
                      $thing2 = $row->Name;
                  }
                  
                  ?>
                  

                  这篇关于使用 MySQLi 连接到多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:(致命错误:在非对象上调用成员函数 bind_param()) 下一篇:带有 mysqli 的 Bind_param 非对象错误

                  相关文章

                  最新文章

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

                  1. <small id='QVs4J'></small><noframes id='QVs4J'>

                    <legend id='QVs4J'><style id='QVs4J'><dir id='QVs4J'><q id='QVs4J'></q></dir></style></legend>