doushenmao9036
doushenmao9036
2019-01-04 10:13

在Laravel中设置sqlite db的自定义路径

I want to use the sqlite db stored in "C:\Folder\my_database.sqlite" , what should i do? I want to use that sqlite db. Can anyone please suggest me a solution?

So i can give the path to sqlite in database.php below:

 'sqlite' => [
            'driver' => 'sqlite',
            'database' => "path to my sqlite db",
            'prefix' => '',
        ],

Also if that is done, then i can change my default connection to sqlite. Like:

DB::setDefaultConnection('sqlite');

Can anyone please suggest me a solution?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • drdyf42880 drdyf42880 2年前

    As the Laravel Documentation states:

    After creating a new SQLite database using a command such as touch database/database.sqlite, you can easily configure your environment variables to point to this newly created database by using the database's absolute path:

     'sqlite' => [
                'driver' => 'sqlite',
                'database' => "C:\Folder\my_database.sqlite",
                'prefix' => '',
            ],
    

    To make it the default connection, just set this in your .env file:

    DB_CONNECTION=sqlite
    
    点赞 评论 复制链接分享
  • douyun3022 douyun3022 2年前

    for set sqlite database you can add absoulate path like this in database.php file..

    'sqlite' => [
            'driver' => 'sqlite',
            'database' =>  'C:\Folder\my_database.sqlite',
            'prefix' => '',
    ],
    

    for set a default sqlite connection update this in your .env file:

    DB_CONNECTION=sqlite
    

    for production update line(number 16) in database.php

    'default' => env('DB_CONNECTION', 'sqlite'),
    

    and then run this command in terminal for remove old configration and create new configration file.

    php artisan config:cache
    
    点赞 评论 复制链接分享
  • doubei8168 doubei8168 2年前

    Open your .env file and set,

    DB_CONNECTION=sqlite
    DB_DATABASE=C:\Folder\my_database.sqlite
    

    further more information you can see: https://laravel.com/docs/5.7/database

    点赞 评论 复制链接分享

相关推荐