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

    • <bdo id='0jWKV'></bdo><ul id='0jWKV'></ul>
  • <legend id='0jWKV'><style id='0jWKV'><dir id='0jWKV'><q id='0jWKV'></q></dir></style></legend>

      <small id='0jWKV'></small><noframes id='0jWKV'>

      1. 在 PHP 上连接 MySQL

        时间:2023-09-25
          <bdo id='iVggU'></bdo><ul id='iVggU'></ul>

          • <legend id='iVggU'><style id='iVggU'><dir id='iVggU'><q id='iVggU'></q></dir></style></legend>

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

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

                <i id='iVggU'><tr id='iVggU'><dt id='iVggU'><q id='iVggU'><span id='iVggU'><b id='iVggU'><form id='iVggU'><ins id='iVggU'></ins><ul id='iVggU'></ul><sub id='iVggU'></sub></form><legend id='iVggU'></legend><bdo id='iVggU'><pre id='iVggU'><center id='iVggU'></center></pre></bdo></b><th id='iVggU'></th></span></q></dt></tr></i><div id='iVggU'><tfoot id='iVggU'></tfoot><dl id='iVggU'><fieldset id='iVggU'></fieldset></dl></div>
                1. 本文介绍了在 PHP 上连接 MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 MySQL 上连接 PHP 应用程序的最佳方式是什么.

                  what is the best way to connect PHP application on MySQL.

                  到目前为止,我有以下连接类.

                  So far I had the below connection classes.

                  class Connection{
                      private static $server = "127.0.0.1";
                      private static $catalog = "schemadb";
                      private static $username = "rootuser";
                      private static $password = "password";
                      public static $current = null;
                  
                      public static function Open(){
                          self::$current = mysqli_init();
                          if(!self::$current){
                              die("Failed to initialize connection");
                          }
                          if(!self::$current->real_connect(self::$server,self::$username,self::$password,self::$catalog)){
                              die("Cannot connect to server");
                          }
                          return self::$current;
                      }
                      public static function Close(){
                          self::$current->close();
                      }
                  }
                  

                  我也有

                  abstract class abstractDAO
                  {
                      protected function getConnection()
                      {
                          $mysqli = new mysqli("127.0.0.1","rootuser","password","schemadb");
                          return $mysqli;
                      }
                  
                  }
                  

                  或者是否有任何其他最佳方法可以在 MySQL 上连接 PHP 应用程序.请指教谢谢..

                  or if there's any other best approach to connect PHP application on MySQL. Please advise thanks..

                  推荐答案

                  您可以尝试使用 PDO 对象:

                  You can try using the PDO object:

                  <?php
                  try {
                      $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
                  
                  } catch (PDOException $e) {
                      print "Error!: " . $e->getMessage() . "<br/>";
                      die();
                  }
                  ?>
                  

                  查看 PHP PDO 文档页面

                  这篇关于在 PHP 上连接 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MySQLi 准备好的语句抱怨“只应通过引用传递变量 下一篇:MySQLI 28000/1045 用户“root"@“localhost"的访问

                  相关文章

                  最新文章

                2. <small id='sDUnx'></small><noframes id='sDUnx'>

                  <tfoot id='sDUnx'></tfoot>
                    <bdo id='sDUnx'></bdo><ul id='sDUnx'></ul>
                  <legend id='sDUnx'><style id='sDUnx'><dir id='sDUnx'><q id='sDUnx'></q></dir></style></legend>

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