php artisan migrate : [PDOException] could not find driver
Asked Answered
S

6

6

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
    
Sacks answered 2/10, 2014 at 7:28 Comment(1)
check out this solutionGlabrate
C
6

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)
Codfish answered 20/2, 2016 at 13:9 Comment(0)
I
4

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

Inerrable answered 2/10, 2014 at 8:36 Comment(8)
yes. tat is the issue. php artisan migrate is not working, that was the original question btwSacks
@diEcho Do you have the same error? What you have defined as default connection and which command you tried? Are you sure you don't have database set also in other environment?Pentode
@diEcho You should run in terminal php --ini to display ini file path and make sure in this file PDO is also enabledPentode
I did, but surprisingly it showing different path of ini file but i cross checked and get that php.ini inside the /lammp/.. file is the working iniSacks
@diEcho Often php cli and standard php have different ini file pathsPentode
Let us continue this discussion in chat.Sacks
.dll is for windows while you use Linux. Probably you should have extension=php_pdo_mysql.so in your /etc/php5/cli/php.iniDistended
this worked becuase i had different php for xampp and different for command -lineLauncelot
E
1

I had the same error and setup I cleared it by adding doctrine/dbal

composer require doctrine/dbal
Eider answered 7/8, 2015 at 12:9 Comment(0)
H
0

Change the .env file.I was also having same problem wih laravel 5.2

I have changed with the following code and it worked fine.

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString

DB_HOST=localhost
DB_DATABASE=todo  /* Use your database Name */
DB_USERNAME=root   /* Use your host Name */
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
Hattiehatton answered 25/2, 2016 at 11:3 Comment(0)
D
0

Edit Your .env file and update Properly.

DB_HOST=127.0.0.1
DB_DATABASE=YOUR DB NAME
DB_USERNAME=YOUR DB USER NAME
DB_PASSWORD= YOUR DB PASSWORD

use 127.0.0.1 instead of localhost..

Draftee answered 31/10, 2017 at 12:46 Comment(0)
R
-2

In your php.ini file uncomment

;extension=php_pdo_mysql.dll

and restart apache server.

Repressive answered 14/2, 2016 at 10:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.