简体   繁体   English

找不到Laravel驱动程序,数据库连接错误?

[英]Laravel driver not found, database misconnection?

I'm getting this error: 我收到此错误:

PDOException in Connector.php line 55: could not find driver
in Connector.php line 55
at PDO->__construct('mysql:host=localhost:8080;dbname=db', 'root', '', array('0', '2', '0', false, false)) in Connector.php line 55

On my .env file I have the credentials as 在我的.env文件上,我的凭据为

DB_HOST=localhost:8080
DB_DATABASE=db
DB_USERNAME=root
DB_PASSWORD=

My wamp is set to port 8080, and when my laravel is viewing on port 8000 via artisan serve. 我的wamp设置为端口8080,并且当我的laravel通过工匠服务在端口8000上查看时。 Is there a disconnect with this? 这有没有联系? All of the pdo modules are in the php.ini 所有的pdo模块都在php.ini中

I don't believe that you can use artisan serve with WAMP, as they are actually two different servers (artisan serve utilizes PHPs built in web server which has no relation to WAMP). 我不认为您可以将artisan服务与WAMP一起使用,因为它们实际上是两个不同的服务器(artisan服务利用与Web服务器无关的内置在Web服务器中的PHP)。

You should checkout this post to get an idea of how to setup Laravel to work with WAMP properly. 您应该查看这篇文章 ,以了解如何设置Laravel使其与WAMP一起正常工作。

You didn't show your list of extensions. 您没有显示扩展列表。

WAMPP WAMPP

  • Check if you have a file php-cli.ini 检查是否有文件php-cli.ini
  • Check or add the following lines to php-cli.ini : 检查以下行或将其添加到php-cli.ini
    • extension=php_pdo_mysql.dll 扩展名= php_pdo_mysql.dll
    • extension=php_mbstring.dll 扩展名= php_mbstring.dll
  • Doesn't php-cli.ini exists? php-cli.ini存在吗? Check or add the lines to your php.ini 检查这些行或将其添加到您的php.ini中
  • Restart WAMPP 重新启动WAMPP

Homestead 家园

I strongly recommend Homestead as your local development server. 我强烈推荐Homestead作为您的本地开发服务器。

Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, HHVM, a web server, and any other server software on your local machine. Laravel Homestead是一个预先包装好的官方Vagrant包装盒,可为您提供一个绝佳的开发环境,而无需在本地计算机上安装PHP,HHVM,Web服务器和任何其他服务器软件。 No more worrying about messing up your operating system! 无需担心搞砸操作系统! Vagrant boxes are completely disposable. 无业游民的箱子是完全一次性的。 If something goes wrong, you can destroy and re-create the box in minutes! 如果出现问题,您可以在几分钟内销毁并重新创建盒子!

Homestead runs on any Windows, Mac, or Linux system, and includes the Nginx web server, PHP 7.0, MySQL, Postgres, Redis, Memcached, Node, and all of the other goodies you need to develop amazing Laravel applications ( https://laravel.com/docs/master/homestead ) Homestead可在任何Windows,Mac或Linux系统上运行,并包括Nginx Web服务器,PHP 7.0,MySQL,Postgres,Redis,Memcached,Node以及开发出色的Laravel应用程序所需的所有其他功能( https:// laravel.com/docs/master/homestead

you are serving from two totally different environments, your wamp is probably using a different php version that your artisan. 您从两个完全不同的环境中服务,您的wamp可能使用的是与您的工匠不同的php版本。 check where both of those php configs are located and install whatever drivers that are missing keep in mind php7 is missing a few pdo drivers if not all. 检查两个php配置的位置,并安装所有缺少的驱动程序。请记住,php7缺少一些pdo驱动程序(如果不是全部)。

Remove port number 8080 from .env file as follows 如下所示从.env文件中删除端口号8080

DB_HOST=localhost
DB_DATABASE=db
DB_USERNAME=root
DB_PASSWORD=

Now try that by placing above values. 现在,通过放置以上值来尝试。

Don't forgot to restart your server. 不要忘记重启服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM