laravel php artisan migrate:[PDOException] 找不到驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26156125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php artisan migrate : [PDOException] could not find driver
提问by diEcho
My system config is Ubuntu 14.04 + XAMPP + Laravel 4installed
我的系统配置是Ubuntu 14.04 + XAMPP + Laravel 4安装
mysql driver is configuredon /opt/lampp/htdocs/larva/app/config/database.php
mysql驱动配置在 /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
在/opt/lampp/etc/php.ini上启用 PDO 扩展
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
生成2014_10_02_114459_create_users.php
php artisan migrate:make create_orders --create=orders
create 2014_10_02_054103_create_orders.php
创建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
[PDOException] 找不到驱动程序
when i run
当我跑步时
php artisan migrate --database=db_larva
it again gives other error
它再次给出其他错误
[InvalidArgumentException]
Database [db_larva] not configured.
[InvalidArgumentException]
未配置数据库 [db_larva]。
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
andphp 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
位置正确吗?
php artisan
在根文件夹内运行 吗?默认表结构里面
function up()
需要多写一些代码,可能是db连接设置php artisan migrate:make create_users --create=users
和 之间的区别php artisan migrate:make create_users --create --table=users
- 我也必须在其他地方配置数据库设置。
- 表前缀可能有问题。
我还没有在代码中的任何地方编写单行来连接数据库。在哪里编写代码中的连接刺,或者那是后期?
php --ini
给出不同的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
回答by Naimuddin Bhuyan
I got this error on xubuntu 14.04. I fixed it in 2 steps:
我在 xubuntu 14.04 上遇到了这个错误。我分两步修复:
- Open a terminal and run
sudo apt-get install php5-mysql
- change the db-host to 127.0.0.1 (instead of using localhost)
- 打开终端并运行
sudo apt-get install php5-mysql
- 将 db-host 更改为 127.0.0.1(而不是使用本地主机)
回答by Marcin Nabia?ek
Parameter --database=
is used to choose DB connection. Your DB connection name is mysql
because you have:
参数--database=
用于选择数据库连接。您的数据库连接名称是mysql
因为您有:
'mysql' =>
so you should run this query using:
所以你应该使用以下方法运行这个查询:
php artisan migrate --database=mysql
However in app/config/database.php
file there is a line:
但是在app/config/database.php
文件中有一行:
'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.
如果设置为,当你想迁移到默认数据库连接时,你mysql
不需要--database
在迁移时传递参数。
php artisan migrate
will be enough
就足够了
EDIT
编辑
In your case you should edit your /etc/php5/cli/php.ini
file to enable PDO extension
在您的情况下,您应该编辑/etc/php5/cli/php.ini
文件以启用 PDO 扩展
回答by Rob Foran
I had the same error and setup I cleared it by adding doctrine/dbal
我有同样的错误和设置,我通过添加学说/dbal 清除了它
composer require doctrine/dbal
回答by Hola
Change the .env file.I was also having same problem wih laravel 5.2
更改 .env 文件。我在 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
回答by HM Nayem
Edit Your .env file and update Properly.
编辑您的 .env 文件并正确更新。
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..
使用 127.0.0.1 而不是 localhost..
回答by Yaroslav Georgitsa
In your php.ini
file uncomment
在您的php.ini
文件中取消注释
;extension=php_pdo_mysql.dll
and restart apache server.
并重新启动apache服务器。