Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Uncaught InvalidArgumentException: Unsupported driver #35

Closed
wfsdaj opened this issue Aug 11, 2020 · 10 comments
Closed

Fatal error: Uncaught InvalidArgumentException: Unsupported driver #35

wfsdaj opened this issue Aug 11, 2020 · 10 comments

Comments

@wfsdaj
Copy link

wfsdaj commented Aug 11, 2020

I am a Chinese user, can not speak English, or a PHP rookie, this is using Google automatic translation, I apologize first. I encountered an error using the model, What did I do wrong?

Fatal error: Uncaught InvalidArgumentException: Unsupported driver

My program code:

App\Controllers\UserController.php

namespace App\Controllers;

use Leaf\Controller;
use App\Models\User;

class UsersController extends Controller
{
    public function index()
    {
        $users = User::all();
        foreach ($users as $user) {
            echo $user->name;
        }
    }

App\Models\User.php

namespace App\Models;

use Leaf\Model;

class User extends Model
{
    protected $table = 'users';
    public $timestamps = false;
}

My database connection:

$db = new Leaf\Db("localhost", "root", "root", "demo");
@mychidarko
Copy link
Member

Hi @wfsdaj, thanks for trying out Leaf. First of all, can you give me some information on your setup? Are you using Leaf on it's own or something like Leaf MVC/Leaf API?

@mychidarko
Copy link
Member

Also, Leaf Models run on eloquent, and not Leaf DB, that may be one of the reasons you're encountering this problem, but I can't say so just yet, which is why I need a more information on your setup

@wfsdaj
Copy link
Author

wfsdaj commented Aug 12, 2020

@mr-phlames thank you for your reply. I use Leaf. I can use the db class normally on the index page.

leaf/index.php

require __DIR__ . "/vendor/autoload.php";
$app = new Leaf\App();
require __DIR__ . "/config/app.php";
require __DIR__ . "/app/routes.php";

$users = $db->select("users", "id, name")->fetchObj();
echo $users->id;        //output 1

$app->run();

@mychidarko
Copy link
Member

Yes the DB class just provides a simple way to use your database. Something you can work with anywhere in your code without worrying about models and stuff like that. So in that case, is you problem resolved or do you still have issues with the database?

@wfsdaj
Copy link
Author

wfsdaj commented Aug 13, 2020

Yes, there are still errors. 😅

@mychidarko
Copy link
Member

Can you confirm something for me? Do you have a .env file in your setup?

@wfsdaj
Copy link
Author

wfsdaj commented Aug 13, 2020

my /.env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=demo
DB_USERNAME=root
DB_PASSWORD=root

my /config/app.php

$app->config([
    'mode' => 'development',
    'debug' => true,
    'templates.path' => './views',
    'log.enabled' => true,
    'cookies.path' => '/',
    'cookies.encrypt' => true,
    'cookies.lifetime' => '20 minutes',
]);

@mychidarko
Copy link
Member

And are you correctly loading the .env variables into your code?

@wfsdaj
Copy link
Author

wfsdaj commented Aug 14, 2020

I thought the .env file was automatically loaded just like laravel。
How can I load .env file correctly? require vlucas/phpdotenv?

@mychidarko
Copy link
Member

Yeah, that should be the easiest way.

Env files are loaded automatically only if you use something like leaf MVC or leaf API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants