swoft-cloud / swoft-doc

📖 Swoft Framework Document(swoft.io)
https://swoft-cloud.github.io/swoft-doc/#/zh-CN/
97 stars 168 forks source link

使用Docker Compose在window10下搭建swoft开发环境,mysql连接错误 #228

Closed akrick closed 5 years ago

akrick commented 5 years ago

{ "code": 0, "error": "(Swoft\Db\Exception\DbException) Pool error is Create connection error(Dsn(mysql:dbname=test;host=127.0.0.1:13306) can not to connected!) file(/var/www/swoft/vendor/swoft/db/src/Connector/MySqlConnector.php) line (43) file=/var/www/swoft/vendor/swoft/connection-pool/src/AbstractPool.php line=250", "file": "At /var/www/swoft/vendor/swoft/db/src/DB.php line 81", "trace": "#0 /var/www/swoft/vendor/swoft/db/src/Query/Builder.php(3324): Swoft\Db\DB::connection('db.pool')

1 /var/www/swoft/vendor/swoft/db/src/Query/Builder.php(2437): Swoft\Db\Query\Builder->getConnection()

2 /var/www/swoft/app/Http/Controller/OrderController.php(35): Swoft\Db\Query\Builder->cursor()

3 /var/www/swoft/vendor/swoft/stdlib/src/Helper/PhpHelper.php(54): App\Http\Controller\OrderController->buy()

4 /var/www/swoft/vendor/swoft/http-server/src/Middleware/DefaultMiddleware.php(75): Swoft\Stdlib\Helper\PhpHelper::call(Array)

5 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\Http\Server\Middleware\DefaultMiddleware->process(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Server\RequestHandler))

6 /var/www/swoft/vendor/swoft/http-server/src/Middleware/ValidatorMiddleware.php(50): Swoft\Http\Server\RequestHandler->handle(Object(Swoft\Http\Message\Request))

7 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\Http\Server\Middleware\ValidatorMiddleware->process(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Server\RequestHandler))

8 /var/www/swoft/vendor/swoft/http-server/src/Middleware/UserMiddleware.php(54): Swoft\Http\Server\RequestHandler->handle(Object(Swoft\Http\Message\Request))

9 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\Http\Server\Middleware\UserMiddleware->process(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Server\RequestHandler))

10 /var/www/swoft/vendor/swoft/view/src/Middleware/ViewMiddleware.php(41): Swoft\Http\Server\RequestHandler->handle(Object(Swoft\Http\Message\Request))

11 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\View\Middleware\ViewMiddleware->process(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Server\RequestHandler))

12 /var/www/swoft/app/Http/Middleware/FavIconMiddleware.php(45): Swoft\Http\Server\RequestHandler->handle(Object(Swoft\Http\Message\Request))

13 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): App\Http\Middleware\FavIconMiddleware->process(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Server\RequestHandler))

14 /var/www/swoft/vendor/swoft/http-server/src/HttpDispatcher.php(80): Swoft\Http\Server\RequestHandler->handle(Object(Swoft\Http\Message\Request))

15 /var/www/swoft/vendor/swoft/http-server/src/Swoole/RequestListener.php(42): Swoft\Http\Server\HttpDispatcher->dispatch(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Message\Response))

16 {main}"

} 其中DB的配置如下: 'db'=> [ 'class' => Database::class, 'dsn' => 'mysql:dbname=test;host=127.0.0.1:13306', 'username' => 'root', 'password' => '123456', 'prefix' => 'vc_', 'charset' => 'utf8', ],

inhere commented 5 years ago

使用 docker compose, mysql 并不在同一个容器里。

host=127.0.0.1:13306 需改为 host=mysql:13306

inhere commented 5 years ago

refer https://github.com/swoft-cloud/swoft/issues/1082