首页 > 解决方案 > 如何修复 laravel 查询异常

问题描述

除 migrate cmd 外,其他 artisan 命令正常工作。当我在终端上运行“php artisan migrate”时,我得到了

Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = test and table_name = migrations and table_type = 'BASE TABLE')

  at /Applications/XAMPP/xamppfiles/htdocs/test/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 

  Exception trace:

  1   PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known")
      /Applications/XAMPP/xamppfiles/htdocs/test/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:host=http://127.0.0.1;port=3306;dbname=test", "root", "", [])
      /Applications/XAMPP/xamppfiles/htdocs/test/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  Please use the argument -v to see more details.

在 .env 文件中

DB_CONNECTION=mysql
DB_HOST=http://127.0.0.1
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=

我已经使用 php -m 检查了 php 启用扩展,其中 mbstring、pdo_mysql、PDO 扩展已经启用

有人可以帮我这有什么问题吗?

标签: phplaravel

解决方案


更改文件DB_HOST中的值.env

DB_HOST=http://127.0.0.1

 DB_HOST=127.0.0.1

推荐阅读