Skip to content
Advertisement

Laravel custom db driver

i know there is a nice way of defining connections via app/config/database.php . But i don’t think there is a driver for me available.

Imagine my db is read from file, like a txt. (Yeah! that’s my client db, sort of).

So in that file, before I

'connections' => 
    'filedb' => array(
        'driver'    => 'what-should-i-put-here'

i need a real driver!

Currently it uses a txt base db but in a future we will be migrating to mysql, so current eloquent implementation will filt excelent for me. But right now i would like to implement a driver for my txt db so i can fully use eloquent now.

Does laravel provides a way to implement your own driver ? In both cases (true or false) , do you have suggestions about it ?

Advertisement

Answer

Laravel doesn’t offer a driver like that.

Laravel’s database component uses PDO internally, which means it can only work with the databases that PDO supports.

You could build a driver that would support the text files you use, but honestly the effort seems bigger than migrating your project to MySQL, regardless its size 🙂

If you need an example, have a look at here: https://github.com/jenssegers/laravel-mongodb. Laravel doesn’t offer MongoDB support, but it can be added with this library. Browse the code – this should help visualise the amount of work that would be needed.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement