0

I'm creating a small mockup for a social network in Laravel 5. I want to use SQLite as my database to keep things small and local. I'm having some trouble, however, getting it to work.

Here's my code (using blade) where I just use a table to display a row in the database:

@extends('layouts.master')

@section('title')
    Testing2
@stop

@section('content')
This is a second test
<a href="/">Back to page 1</a>

<table>
    <tr><th>Author</th>
        <th>Text</th></tr>
    @foreach($posts as $post)
        <tr>
            <td>
                {{$posts->Author}}
            </td>
        </tr>
        <tr>
            <td>
                {{$posts->Text}}
            </td>
        </tr>
    @endforeach
</table>
@stop

"Author" and "Text" being 2 columns in my database. Here is the Route I use to generate the page:

Route::get('test2', function () {
    $sql = "select * from Posts";
    $posts = DB::select($sql);
    return View::make('test2')->withPosts($posts);
});

I know my database is there, I've placed it in the /database directory of my app:

enter image description here

Lastly, I modified the config\database.php file to set SQLite as the default database:

enter image description here

When I try and view the blade page using the Route function, I get the following error: "SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it."

I'm doing something wrong somewhere with connecting to my database, but I don't know what. Have I set it up properly?

2
  • 2
    What does your .env file look like? It is looking inside your .env file first for your DB_CONNECTION and then if that doesn't exist it will use the sqlite definition you have set. Commented Apr 19, 2016 at 3:41
  • This is what my .env file looks like, should I change anything there? puu.sh/onGHZ/a5bca3bcac.png Commented Apr 19, 2016 at 4:22

2 Answers 2

1

Place your database in the storage folder and mention the path in the database. Also you should have the php driver installed.

Do this in the app/config/database.php:

<?php
return array(
'default' => 'sqlite',
'connections' => array(
    'sqlite' => array(
        'driver'   => 'sqlite',
        'database' => __DIR__.'/../database/production.sqlite',
        'prefix'   => '',
    ),
),
);
?>
Sign up to request clarification or add additional context in comments.

Comments

0

You have set your DB_CONNECTION inside your .env file as mysql.

The line 'default' => env('DB_CONNECTION', 'sqlite'), basically says look in my .env file first; if there is a setting set for DB_CONNECTION then use that, if there isn't then use sqlite.

It's an easy fix, just change the DB_CONNECTION config value to sqlite instead of mysql.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.