Laravel - Migration to PGSQL error - php

i started a project with Laravel and PostgreSQL but i can not make the migration.
[Illuminate\Database\QueryException]
could not find drive (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations)
[PDOException]
could not find driver
I checked my php.ini and i've uncomment the lines:
extension=php_pdo_pgsql.dll
extension=php_pgsql.dll
I restarted the server and when i tried again, the console gives me the same error. I checked my .env file in laravel and it's okay (i think)
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravelPSQL
DB_USERNAME=postgres
DB_PASSWORD=password
and also i checked the database.php and it's okay.
'default' => env('DB_CONNECTION', 'pgsql'),
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
]
The last thing i did, was make a file with the function phpinfo() to see if the files of pgsql was enabled and yes.
Honestly i don't know what is happening. I tried in Wamp64, and XAMPP...and nothing. PD. I using Windows 10

I faced the same problem but I solved it by editing my XAMP php.ini file
In php.ini file I un-comment this line:
extension=pgsql
and then it starts working.

Related

PHP - Laravel Corcel configuration issue with WP database

The Laravel log file reports an error with the configuration. I am configuring the WP database in the .env as being pointed out in the official docs.
The error I got in the Laravel logs:
[2019-08-06 10:23:44] local.ERROR: Database [corcel] not configured.
{"exception":"[object] (InvalidArgumentException(code: 0): Database
[corcel] not configured. at
/Applications/MAMP/htdocs/platform/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:152)
In the config/database.php I have a separate connection for Corcel:
'corcel' => [ // for WordPress database (used by Corcel)
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_WP_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => 'wp_',
'strict' => false,
'engine' => null,
],
...and in the config/corcel.php file I have this line:
'connection' => 'corcel',
...that corresponds to the connection added in config/database.php
The configuration in the .env file I added the WordPress database which should be the source for Corcel:
DB_WP_DATABASE=my_wp_database
The rest of the .env file is the same and I still got no idea why is this throwing config error.
Your config may be cached, could you try running
php artisan config:clear
Is the error happening when you are trying access data? If so you need to specify the connection on your query.
DB::connection('corcel')->table('table_name')
If you are using MAMP, you may need to use unix_socket. In that case you can include unix_socket on the database config like,
'corcel' => [
.....
'unix_socket' => env('DB_SOCKET', ''),
.....
],
On the environment variable(.env file), you may need to use the following,
DB_SOCKET="/Applications/MAMP/tmp/mysql/mysql.sock"

PHP Laravel could not migrate files to database

I'm trying to connect with PHP and MySQL through the database using Laravel doing:
php artisan migrate but I'm experiencing a common error:
"Illuminate\Database\QueryException : could not find driver"
(I'm using XAMPP to start up the server if that makes a difference)
The values I changed in database.php:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3308'),
'database' => env('DB_DATABASE', 'test2'),
'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,
],
I also changed the .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3308
DB_DATABASE=test2
DB_USERNAME=root
DB_PASSWORD=
The things I did were:
See if the extension=pdo_mysql is uncommented which it was.
Typed in php artisan migrate:refresh
Restarted Xampp
Deleted and recreated the migration file. Also incremented the last digit of the number (taken advice from one of the answers)
Check the version (which is the latest)
composer update
composer require doctrine/dbal
Check to see if pro_mysql is activated on your install.
You can do this by creating a file and adding the following:
phpinfo();
Then navigate to it in your browser. If it is activated you will see it in the list.
Here is some more info:
http://php.net/manual/en/function.phpinfo.php
Hope that helps.

connecting postgres with laravel

Hello i'm trying to connect laravel 5.4 with postgres, after updating the database configuration file and running php artisan migrate, the following error appears:
[Illuminate\Database\QueryException]
could not find driver (SQL: select * from information_schema.tables where t
able_schema = public and table_name = migrations)
[PDOException]
could not find driver
this is my .env file
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=Portail
DB_USERNAME=php
DB_PASSWORD=php
and this is my database.php file
'default' => env('DB_CONNECTION', 'pgsql'),
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'Portail'),
'username' => env('DB_USERNAME', 'php'),
'password' => env('DB_PASSWORD', 'php'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer', ],
and i use phpPgAdmin normally
sudo apt-get install php-pgsql. This is the command to install php pgsql driver in linux
I had a similar problem using on Ubuntu18.04 using php7.4
Solution:
First check you PHP version with php -v, in my case the version come out to be php7.4 so installed the necessary driver with apt-get install php7.4-pgsql
Finally restart the PHP server
I found the solution there are two php.ini files
C:\wamp64\bin\apache\apache2.4.9\bin
C:\wamp64\bin\php\php7.0.10
i must do uncommented php_pdo_pgsql.dll and php_pgsql.dll in the two files
thanks for your help all

Laravel: Access denied for user homestead at localhost

I just started a new Laravel project and I am having some database connectivity problem. First of all, I have only the User model which comes with the package. It has a migration as well. I updated my env file for the database path like this:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel_project1
DB_USERNAME=root
DB_PASSWORD=''
The problem is, when I ran migrate command
php artisan migrate
It created those migrations in my database. But now when I am simply trying to do User::all(); I am having some trouble with this error:
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `users`)
I have even cleared my config cache with this command:
php artisan config:clear
I don't understand what's wrong.
EDIT:
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'port' => env('DB_PORT', '3306'),
'database' => 'laravel_project1',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
This seems to solve the problem but I don't understand why env file is not working as it is the recommended way I believe.
The way Laravel's database config works is reading the /config/database.php file, so if you wan't Laravel to read your configuration from your .env file, you just have to make some changes in the /config/database.php for example:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'laravel_project1'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
So now the /config/database.php file will read your .env file and if it fails to read it will have the default config (Which is the second argument of each env() function above...)
To close this question, as Vasil Gerginski said in comments below my question. Restarting solved the problem.
When artisan starts, it caches your config. So even if you change it, it won't take affect until you restart artisan server.

Laravel: Error [PDOException]: Could not Find Driver in PostgreSQL?

I am trying to connect PostgreSQL with Laravel 5.0 but facing exception "Could not Find Driver in PostgreSQL".
I have tried this solution but cannot connected with PostgreSQL
stackoverflow answer
My database.php config file is following
'default' => 'pgsql'
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forgeUser'),
'password' => env('DB_PASSWORD', '****'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'port' => 5432,
]
PDO extensions are enabled in php.ini
extension=php_pdo.dll
extension=php_pdo_pgsql.dll
when i run following command
php artisan migrate
it gives error
[PDOException] could not find driver
Its working fine when we connect PostgreSQL with Core PHP.
is there any driver still missing in Laravel? Please guide me.
Thank You
You must be ssh'd into your homestead or vagrant box. Then try to migrate.

Categories