php - 如何修复 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 扩展已经启用
有人可以帮我这有什么问题吗?
解决方案
更改文件DB_HOST
中的值.env
DB_HOST=http://127.0.0.1
至
DB_HOST=127.0.0.1
推荐阅读
- r - R:如何将对象及其值放入数据框中
- regex - sed 脚本删除空行之前的行
- python - 将经过身份验证的用户关联到形成对象 Djano
- c++ - CMake'ifying Boost Jam 文件:Windows 库名称
- wordpress - Woocommerce - 我需要在商店和产品页面显示一个单位的价格(7 美元),但收取产品的实际价值(100 件)
- c# - 检查数据表是否包含某个值
- python - 使用 Conda 和 matplotlib 的英特尔 MKL 错误:macOS 上的“库未加载:@rpath/libiomp5.dylib”
- html - 和有什么区别和
- r - 在R中组合数据帧而不用空白覆盖数据
- python - 使用两个 Pandas 数据框创建列表列表