Php artisan migrate: [PDOException] could not find driver

My system configuration Installed Ubuntu 14.04 + XAMPP + Laravel 4

The 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 a 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 the terminal what i did

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

he gives an error

[PDOException] could not find driver

when i started

 php artisan migrate --database=db_larva 

he gives another error again

[InvalidArgumentException]
Database [db_larva] is not configured.

Please tell me what am I doing wrong?

My suggestion:

  • Is the place right? do php artisan inside root folder?

  • The default table structure inside function up() needs to be written one more code, there 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 also need to configure the database settings elsewhere. Table prefix
  • may be problematic.
  • I am not writing a single line to connect a database anywhere else in the code. where to write a message in code, or is it a later stage?

  • php --ini gives another php ini path?

     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 
+5
source share
6 answers

I got this error on xubuntu 14.04. I installed it in 2 stages:

  • Open a terminal and run sudo apt-get install php5-mysql
  • change db-host to 127.0.0.1 (instead of using localhost)
+6
source

The --database= parameter --database= used to select a database connection. The name of your mysql DB connection, because you have:

 'mysql' => 

therefore, you should run this query using:

 php artisan migrate --database=mysql 

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

 'default' => 'mysql', 

If you set the mysql value, you do not need to pass the --database parameter when migrating, when you want to switch to the default database connection.

 php artisan migrate 

will be sufficient

EDIT

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

+4
source

I had the same error and setting that I cleared by adding doctrine / dbal

 composer require doctrine/dbal 
+1
source

Modify the .env file. I also had the same issue with laravel 5.2

I changed this code and 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 
0
source

Correctly edit the .env file and update it.

 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 ..

0
source

In your php.ini uncomment php.ini

 ;extension=php_pdo_mysql.dll 

and restart the Apache server.

-2
source

Source: https://habr.com/ru/post/1203844/


All Articles