Hello, everyone! I want to ask a question about error I get with command php artisan migrate.
So here's the error itself:
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = laravel_app_db and table_name = migrations and table_type = 'BASE TABLE')
at C:\MAMP\htdocs\laravel_app\vendor\laravel\framework\src\Illuminate\Database\Connection.php:759
755▕ // If an exception occurs when attempting to run a query, we'll format the error
756▕ // message to include the bindings with SQL, which will make this exception a
757▕ // lot more helpful to the developer instead of just the database's errors.
758▕ catch (Exception $e) {
➜ 759▕ throw new QueryException(
760▕ $query, $this->prepareBindings($bindings), $e
761▕ );
762▕ }
763▕ }
1 C:\MAMP\htdocs\laravel_app\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("could not find driver")
2 C:\MAMP\htdocs\laravel_app\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct("mysql:host=127.0.0.1;port=8889;dbname=laravel_app_db", "root", "root", [])
I'm on Windows 10 Pro and I got PHP version 8.1.0 and MAMP PRO 5.
MySQL settings in MAMP PRO 5:
Ports settings in MAMP PRO 5:
Created database in phpMyAdmin:
I was watching the 3 hour Laravel tutorial and got stuck on the moment, where the guy was migrating tables by php artisan migrate command. I successfully installed Laravel and created a bunch of pages there.
Here's what I did trying to solve the problem:
- enabled php_openssl.dll, extension=php_mysqli.dll and extension=php_pdo_mysql.dll extensions in php.ini file from this path
C:\MAMP\bin\php\php8.1.0
- changed DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME and DB_USERNAME in .env file
- edited AppServiceProvider.php file like you will see down below
- edited database.php file like you will see below AppServiceProvider.php file
Literally NOTHING happens, I still get the error! Maybe I have wrong PHP version. Maybe this guy uses XAMPP local web-server instead of MAMP PRO 5. I really don't know what to do.
AppServiceProvider.php file:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema; //<---- added this line
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191); //<---- added this line
}
}
MySQL properties from database.php file:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '8889'),
'database' => env('DB_DATABASE', 'laravel_app_db'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'root'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Additional info:
Needed extensions from php.ini file:
extension=php_bz2.dll
extension=php_gd.dll
;extension=php_gd2.dll
extension=php_gettext.dll
extension=php_mbstring.dll
extension=php_exif.dll
extension=php_mysqli.dll
extension=php_pdo_sqlite.dll
extension=php_sqlite3.dll
extension=php_curl.dll
extension=php_openssl.dll
extension=php_imagick.dll
extension=php_pdo_mysql.dll
;extension=php_apc.dll
;extension=php_apcu.dll
;extension=php_eaccelerator.dll
;extension=php_xcache.dll
;zend_extension=php_opcache.dll
Database properties from .env file:
APP_NAME=laravel_app
APP_ENV=local
APP_KEY=base64:TIlPzLirZ 9Jw6Am0m4XDEodGxmbc8wXSAKQ0XDb5fU=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=8889
DB_DATABASE=laravel_app_db
DB_USERNAME=root
DB_PASSWORD=root
CodePudding user response:
So, I fixed this.
I read these posts:
https://stackoverflow.com/questions/34212578/how-do-i-install-pdo-drivers-for-php-on-windows
https://stackoverflow.com/questions/30182984/sqlstatehy000-2002-php-network-getaddresses-getaddrinfo-failed-name-or-ser
What did I do:
- I changed 544 line in
php.ini
from thisextension_dir = "C:\MAMP\bin\php\php5.5.0\ext\"
to thisextension_dir = "C:\MAMP\bin\php\php8.1.0\ext"
- Then I got the error from the second post SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
- I solved the second error by running this command
php artisan config:clear
- And then I finally got successful message from cmd