Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php artisan migrate : [PDOException] could not find driver

My system config is Ubuntu 14.04 + XAMPP + Laravel 4 installed

mysql driver is configured on /opt/lampp/htdocs/larva/app/config/database.php

'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'db_larva',
            'username'  => 'root',
            'password'  => '*****',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => 'tbl_',
        ),

PDO extension is enabled on /opt/lampp/etc/php.ini

extension=php_pdo_mysql.dll

create table using

php artisan migrate:make create_users --create=users 

which generate 2014_10_02_114459_create_users.php

php artisan migrate:make create_orders --create=orders

create 2014_10_02_054103_create_orders.php

now on terminal what I did

cd /opt/lampp/htdocs/larva/ 
php artisan migrate

it gives error

[PDOException] could not find driver

when i run

php artisan migrate --database=db_larva

it again gives other error

[InvalidArgumentException]
Database [db_larva] not configured.

Please guide me what I am doing wrong?

My guess:

  • Is location correct? do run php artisan inside the root folder?

  • Default table structure inside function up() need to write some more code, may be db connection settings

  • difference between php artisan migrate:make create_users --create=users and php artisan migrate:make create_users --create --table=users
  • I have to configure database settings somewhere else too.
  • table prefix can be problematic.
  • I haven't write single line to connect database, anywhere in the code yet. where to write the connection sting in code, or that is a later stage?

  • php --ini gives different path of php ini?

    Configuration File (php.ini) Path: /etc/php5/cli
    Loaded Configuration File:         /etc/php5/cli/php.ini
    Scan for additional .ini files in: /etc/php5/cli/conf.d
    Additional .ini files parsed:      /etc/php5/cli/conf.d/05-opcache.ini,
    /etc/php5/cli/conf.d/10-pdo.ini,
    /etc/php5/cli/conf.d/20-json.ini,
    /etc/php5/cli/conf.d/20-mcrypt.ini,
    /etc/php5/cli/conf.d/20-readline.ini,
    /etc/php5/cli/conf.d/20-xdebug.ini
    
like image 968
diEcho Avatar asked Oct 02 '14 07:10

diEcho


2 Answers

I got this error on xubuntu 14.04. I fixed it in 2 steps:

  1. Open a terminal and run sudo apt-get install php5-mysql
  2. change the db-host to 127.0.0.1 (instead of using localhost)
like image 125
Naimuddin Bhuyan Avatar answered Sep 22 '22 03:09

Naimuddin Bhuyan


Parameter --database= is used to choose DB connection. Your DB connection name is mysql because you have:

'mysql' =>

so you should run this query using:

php artisan migrate --database=mysql

However in app/config/database.php file there is a line:

'default' => 'mysql',

If you set it to mysql you don't need to pass --database parameter when migrate when you want to migrate to default database connection.

php artisan migrate

will be enough

EDIT

In your case you should edit your /etc/php5/cli/php.ini file to enable PDO extension

like image 22
Marcin Nabiałek Avatar answered Sep 24 '22 03:09

Marcin Nabiałek