I'm trying to execute the php artisan migrate command to create a table in phpmyadmin
But its showing error of
"could not find driver"
I have made the php artisan serve and it worked
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'testdb'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'xxxx'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_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'),
]) : [],
],
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testdb
DB_USERNAME=root
DB_PASSWORD=xxxx
This is the error showing in the command line:
Illuminate\Database\QueryException : could not find driver
(SQL: select * from information_schema.tables where table_schema =
testdb and table_name = migrations)
at C:\AppServ\www\laravel2\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("could not find driver")
C:\AppServ\www\laravel2\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=testdb", "root", "xxxx", [])
C:\AppServ\www\laravel2\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
it's expected to show "tables created successfully" and also created in phpmyadmin
Make sure the mysql is running on your machine if you're using homestead mysql port might be 33060 ..
to clarify if mysql is running open the terminal on mac or linux or command line on windows and write
mysql -u root
if you got the error that mean the mysql is not running.
You are missing the php-mysql driver for PHP, you can check it by executing php -i | grep mysql
If you are missing it you have to install it considering your system type, for example if you were working on a php7.2 system on ubuntu, you should do:
sudo apt-get install php7.2-mysql
Change in config/database.php file according to this:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_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'),
]) : [],
],
Check here : Link
Open the .env file and edit it. just set up correct database credentials
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Your Database Username
DB_PASSWORD= // Your Database Password, If no password is set then just clear it
After .env edit, must be clear cache: php artisan config:cache
Related
I am trying to migrate and already installed Xampp and also already uncomment the ";extension=php_pdo_mysql.dll" and ";extension=pdo_mysql" in the php.ini file, and still getting that error:
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = rav2 and table_name = migrations and table_type = 'BASE TABLE')
PDOException::("could not find driver")
Any ideas?
Thank you!
Maybe, you don't set correct db states at .env.
Check your .env params that you want to connect your database.
for example, table_type = 'BASE TABLE' seems to be wrong?
first, check your php.ini is correct like
# Windows
extension=php_pdo_mysql.dll
# Linux
extension=php_pdo_mysql.so
Is that uncommented ?
if you have ;,remove that.
and you need to restart your xampp after fixing that php.ini.
do /etc/init.d/httpd restart
also your laravel env may be wrong ... so fix .env like:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= your database name
DB_USERNAME= your database user name
DB_PASSWORD= your database password
and you should check your database config like:
/config/database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'your database name'),
'username' => env('DB_USERNAME', 'your database user name'),
'password' => env('DB_PASSWORD', 'your database password'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_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'),
]) : [],
],
I am trying to migrate for the first time and am getting the below error. Any help will be appreciated.
PS C:\Users\lenovo\Desktop\projects\instalar> php artisan migrate
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = instalar and table_name = migrations and table_type = 'BASE TABLE')
at C:\Users\lenovo\Desktop\projects\instalar\vendor\laravel\framework\src\Illuminate\Database\Connection.php:678
674▕ // If an exception occurs when attempting to run a query, we'll format the error
675▕ // message to include the bindings with SQL, which will make this exception a
676▕ // lot more helpful to the developer instead of just the database's errors.
677▕ catch (Exception $e) {
➜ 678▕ throw new QueryException(
679▕ $query, $this->prepareBindings($bindings), $e
680▕ );
681▕ }
682▕
1 C:\Users\lenovo\Desktop\projects\instalar\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("could not find driver")
2 C:\Users\lenovo\Desktop\projects\instalar\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct()
here is my .env mysql settings
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=instalar
DB_USERNAME=root
DB_PASSWORD= ffgjjyufgf`
database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_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'),
]) : [],
],
some posts suggested that the problem could be in my php.ini but I closed checked it out but I think it is ok from the solution they offered. Below is my php.ini:
extension_dir="/xampp/php/ext"
extension=mysqli
;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
;extension=odbc
;extension=openssl
;extension=pdo_firebird
extension=php_pdo_mysql
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=shmop
So first thing first i've created migration tables and it successfully migrated and seeded. i've change the .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=jj
DB_USERNAME=root
DB_PASSWORD=
i've tried to change the database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'jj'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_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'),
]) : [],
],
but i'm still unable to login. the error says SQLSTATE[HY000] [1049] Unknown database 'laravel' (SQL: select * from `users` where `username` = admin limit 1) even though i've migrated and seeded the database
If the configuration looks okay and you are 100% certain that MySQL is running, you might want to clear the configs and caches.
php artisan config:clear
php artisan cache:clear
Try the config one and then the cache if the problem isn't resolved by the first command.
You can read more about the commands here
I am new to Laravel so started creating api. I already have MySQL database at local and I am trying to connect with local database but getting following logtrace.
php artisan migrate
PDOException : SQLSTATE[HY000] [2006] MySQL server has gone away
at /Users/sandeeparmal/...../vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
66| if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) {
67| return new PDOConnection($dsn, $username, $password, $options);
68| }
69|
> 70| return new PDO($dsn, $username, $password, $options);
71| }
72|
73| /**
74| * Determine if the connection is persistent.
Exception trace:
1 PDO::__construct("mysql:host=127.0.0.1;port=8080;dbname=sample_server", "root", "", [])
/Users/sandeeparmal/...../vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 Illuminate\Database\Connectors\Connector::createPdoConnection("mysql:host=127.0.0.1;port=8080;dbname=sample_server", "root", "", [])
/Users/sandeeparmal/...../vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:100
Here is my .env file :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=8080
DB_DATABASE=sample_server
DB_USERNAME=root
DB_PASSWORD=
Here is my database.php :
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '8080'),
'database' => env('DB_DATABASE', 'forcity_server'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_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'),
]) : [],
]
I tried to find solution and got solution from here but still it's not working. I applied same on local database.
I updated to laravel 6, so I updated PHP because laravel 6 uses 7.2+
by default there wasn't php.ini and when generated, extension was off so I tried migration too and found out this
Check php.ini, there is one row
;extension=pdo_mysql
make it
extension=pdo_mysql
save and restart apache
I just can't connect with my database in laravel, it's give me an error
SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected (SQL: select count(*) as aggregate from users where email = )
.env my database name is=empty
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=empty
DB_USERNAME=root
DB_PASSWORD=
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'empty'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_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'),
]) : [],
],
Thank you in advanced.
You shouldn't be using reserved keywords at all to names of tables, columns, functions, stored_procedures, views, database.
Please find below link for reserved keywords in MySQL.
https://dev.mysql.com/doc/refman/8.0/en/keywords.html#keywords-removed-in-current-series.
If still facing some problems. follow below commands.
composer update
composer dump-autoload
php artisan config:cache
php artisan view:clear
php artisan route:clear