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

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

        <legend id='f8GkU'><style id='f8GkU'><dir id='f8GkU'><q id='f8GkU'></q></dir></style></legend><tfoot id='f8GkU'></tfoot>
          <bdo id='f8GkU'></bdo><ul id='f8GkU'></ul>
      2. 在 PHP 中创建到 PDO 的连接时出错

        时间:2023-10-05
        <i id='hElfE'><tr id='hElfE'><dt id='hElfE'><q id='hElfE'><span id='hElfE'><b id='hElfE'><form id='hElfE'><ins id='hElfE'></ins><ul id='hElfE'></ul><sub id='hElfE'></sub></form><legend id='hElfE'></legend><bdo id='hElfE'><pre id='hElfE'><center id='hElfE'></center></pre></bdo></b><th id='hElfE'></th></span></q></dt></tr></i><div id='hElfE'><tfoot id='hElfE'></tfoot><dl id='hElfE'><fieldset id='hElfE'></fieldset></dl></div>
        <legend id='hElfE'><style id='hElfE'><dir id='hElfE'><q id='hElfE'></q></dir></style></legend>

          <tbody id='hElfE'></tbody>
          <bdo id='hElfE'></bdo><ul id='hElfE'></ul>
        • <small id='hElfE'></small><noframes id='hElfE'>

                  <tfoot id='hElfE'></tfoot>
                • 本文介绍了在 PHP 中创建到 PDO 的连接时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  今天为了迁移到php 5.30,我把最新版的lampp卸载重装了,突然一个很简单的app连接mysql数据库失败.我正在使用 PDO 进行连接,并收到以下错误:

                  Today, I removed and reinstalled the latest version of lampp in order to move to php 5.30, and suddenly a very simple app is failing to connect to the mysql database. I'm using PDO to connect, and receiving the following error:

                  Warning: PDO::__construct() [pdo.--construct]: [2002] Invalid argument (trying to connect 
                  via unix://) in /home/raistlin/www/todoapp/home.php on line 9
                  
                  Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002]
                  Invalid argument' in /home/raistlin/www/todoapp/home.php:9 Stack trace: #0
                  /home/raistlin/www/todoapp/home.php(9): PDO->__construct('mysql:host=loca...', 'USER', 
                  'PASSWORD') #1 {main} thrown in /home/raistlin/www/todoapp/home.php on line 9
                  

                  为了调试,我目前没有捕捉到错误.

                  I am not catching the error at the moment, for the sake of debugging it.

                  以下代码足以在我的系统上复制该问题:

                  The following code is enough to replicate the issue on my system:

                  <?php
                  $DBACCESS = array(
                      "connstring"=>"mysql:host=localhost;dbname=todoapp",
                      "host"=>"localhost",
                      "user"=>"user",
                      "password"=>"password",
                      "todoapp"=>"todoapp"
                      );
                  
                      echo implode('<br >',$DBACCESS);
                  
                      $dbh = new PDO($DBACCESS['connstring'],$DBACCESS['user'],$DBACCESS['password']);
                  
                      $dbh = null;
                  ?>
                  

                  在网上查找,我发现一两个其他人遇到了同样的问题,但他们都没有收到回复,更不用说有效的回复了.有谁知道发生了什么?我在配置中遗漏了什么吗?我需要做什么来修复它?

                  Looking online, I've found one or two other people with the same issue, but none of them have received a response, much less a working one. Does anyone know what is happening? Is there something I missed in the configuration? What do I need to do to fix it?

                  推荐答案

                  通常意味着你需要指定 TCP/IP (1),或者告诉 MySQL 你的 Unix socket 在哪里 (2):

                  Usually means that you need to specify TCP/IP (1), or tell MySQL where your Unix socket is (2):

                  1. "mysql:host=127.0.0.1" 或 "mysql:host=localhost;port=3306"
                  2. "mysql:unix_socket=/var/run/mysqld/mysqld.sock"

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

                  上一篇:如何使用 PHP PDO 从 Mac 连接到 Sql Server? 下一篇:如何使用 PDO 获取一行

                  相关文章

                  最新文章

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

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

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