drqyxkzbs21968684 2015-07-10 16:43
浏览 199
已采纳

Laravel连接错误

I've eventually made my connection with mysql instead of mssql because it was not working (I'm working with laravel). But now it's still not working. I receive the error:

SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected (SQL: create table `users` (`id` int unsigned not null auto_increment primary key, `username` varchar(32) not null, `email` varchar(320) not null, `password` varchar(60) not null, `created_at` timestamp default 0 not null, `updated_at` timestamp default 0 not null) default character set utf8 collate utf8_unicode_ci)

I'm connection to my localhost with a wamp server. This is my code:

> 'mysql' => [
>             'driver'    => 'mysql',
>             'host'      => env('localhost'),
>             'database'  => env('test'),
>             'username'  => env('root'),
>             'password'  => env(''),
>             'charset'   => 'utf8',
>             'collation' => 'utf8_unicode_ci',
>             'prefix'    => '',
>             'strict'    => false,
>         ],

And my env :

'default' => env('mysql', 'mysql'),

EDIT

.env:

DB_HOST=localhost
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=
  • 写回答

2条回答 默认 最新

  • douduan5073 2015-07-11 17:00
    关注

    syntax env('key','default') with:

    key is key before = in env file

    default is default value if key not exist in env file

    please edit as follows:

    > 'mysql' => [
    >             'driver'    => 'mysql',
    >             'host'      => env('DB_HOST', 'localhost'),
    >             'database'  => env('DB_DATABASE','db_name'),
    >             'username'  => env('DB_USERNAME','root'),
    >             'password'  => env('DB_PASSWORD',''),
    >             'charset'   => 'utf8',
    >             'collation' => 'utf8_unicode_ci',
    >             'prefix'    => '',
    >             'strict'    => false,
    >         ],
    

    P/s: excuse me my English.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化