Monday 6 November 2017

Using SQLite in Laravel Applications

 I have been playing with Laravel and MySQL just recently and I have been enjoying using it on one of my recent project.    It's an eCommerce system done with Laravel 5.3 with Paypal and Stripe Payment.  I have implemented a authorize and capture mechanism.   

I've been using MySQL for database which works as expected but my problem is I'm using 3 machines for my development.   I don't want to use any cloud database like AWS MySQL or Google cloud db, because it's a paid one and apparently I'm not online always.   Things like I can work even in train (really hardworking right?) wherein internet is superslow.

Now comes SQLite.   SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files. A complete SQL database with multiple tables, indices, triggers, and views, is contained in a single disk file.  Meaning a portable database which will solve my dillema.


To use SQLite on Laravel

Create a database laravel.sqlite file in the database folder of your laravel project.   You might need to download SQLite browser in http://sqlitebrowser.org/

/your-project/database/laravel.sqlite



Open your database.php file in the config folder of your project and make sure what you see in the image below is the same in your project.





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


Go to your .env file and and change your DB_CONNECTION to
'sqlite'. Another thing you have to do is change DB_DATABASE to the path of your laravel.sqlite on your local computer.  You can leave the port, username and password.




DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=D://github/admin-dash/database/laravel.sqlite
DB_USERNAME=root
DB_PASSWORD=
Share:

0 comments:

Post a Comment

Popular Posts

Recent Posts

Pages

Powered by Blogger.

About Me

My photo
For the past 10 years, I've been playing with codes using PHP, Java, Rails. I do this for a living and love new things to learn and the challenges that comes with it. Besides programming I love spending time with friends and family and can often be found together catching the latest movie or planning a trip to someplace I've never been before.