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
Related
I need a help to connect Laravel with PostgreSQL database in Linux (ElementaryOS based on ubuntu 14.04)
I already installed the php-pgsql driver and restarted the apache2 and postgresql services.
This is my php.ini:
extension=pgsql.so
extension=pdo_pgsql.so
This is the query:
$usuario = DB::select('select * from usuario');
Error in laravel:
"could not find driver (SQL: select * from usuario)"
My .env:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=minha_db
DB_USERNAME=meu_user
DB_PASSWORD=minha_senh3
database.php
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'minha_db'),
'username' => env('DB_USERNAME', 'meu_user'),
'password' => env('DB_PASSWORD', 'minha_senha'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
(Posted on behalf of the question author).
I've solved it using:
sudo apt-get install php7.0-pgsql
Before I've installed the package without specification the version using this command:
sudo apt-get install php-pgsql
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.
Intro. My laravel app was using mysql, now it needs to be hosted in the network of the company I am working ( I am a remote-worker). And this company are Microsoft peeps, so I need to integrate the laravel to their SQL Server.
I have this in my .env
DB_CONNECTION=sqlsrv
DB_HOST=ip.address.of.server
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=my_username
DB_PASSWORD=my_password
After using the php artisan migrate
Error:
[PDOException]
could not find driver
I am using Ubuntu, a remote box dedicated for me (from my employer). I have tried using sql server in my laravel app before (using my Windows PC). As far as I remember, I edited some texts in the xampp php.ini. As a newbie Linux user, it is too hard for me (since i was using only CLI).
EDITED ( new version )
So I already got the connectivity from Ubuntu to the Database server. I used the the sqlcmd -S <host> -U <username>
and I tested the queries (such as SELECT * from users_data) and it works.
Now, I modified the config/database.php and I added this.
'sqlsrv' => [
'driver' => 'MSSQL',
'host' => env('DB_HOST', 'host.of.the.database'),
'database' => env('DB_DATABASE', 'my_database'),
'username' => env('DB_USERNAME', 'my_username'),
'password' => env('DB_PASSWORD', 'my_pass'),
'port' => '1433',
'prefix' => '',
],
but I got an Error:
[InvalidArgumentException]
Unsupported driver [MSSQL]
"MSSQL" is the name I use to configure the FreeTDS.
For those who came after
Make sure of the PHP version you use (for me homestead currently using php 7.1, so I installed php7.1-sybase)
sudo apt-get install freetds-common freetds-bin unixodbc php7.1-sybase
And the driver is
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'port' => env('DB_PORT', '1433'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
]
You can make sure that the connection information is correct using tsql
TDSVER=8.0 tsql -H Host -U Username -D DatabaseName -p 1433 -P Password
Note: After that you need to re-run command php artisan serve.
Also had the could not find driver error, resolved the issue after installing following packages:
sudo apt-get install freetds-common freetds-bin unixodbc php5-sybase
However i am using the sqlsrv driver, here's my config/database.php:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
When installing sybase, ensure that it matches up with the version that your VM uses.
Run
php --version
and then install the right sybase version:
sudo apt-get install freetds-common freetds-bin unixodbc php7.#-sybase
If you're getting encoding errors, you'll need to update your freedts and php.ini configuration as well. Change the /etc/freetds/freetds.conf so that it looks like:
[global]
# TDS protocol version
tds version = 8.0
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
client charset = UTF-8
# A typical Sybase server
[egServer50]
host = symachine.domain.com
port = 5000
tds version = 5.0
# A typical Microsoft server
[egServer70]
host = ntmachine.domain.com
port = 1433
tds version = 7.0
[mssql]
host =
Port = 1433
tds version = 8.0
Add this to your php.ini:
client charset = UTF-8
Always run sudo apt-get upgrade before trying to run these commands.
Thanks, these answers helped great. Please let me explain what I did using laravel/homestead vagrant box version 7.1.0 and PHP 7.3.
I ran the command sudo apt-get install freetds-common freetds-bin unixodbc php7.3-sybasein my vagrant homestead virtual box.
This command prompted me twice to either keep the local php.ini configuration file or use the "installer's version". I chose to use the installer's version both times, and everything worked great. Here is my database.php file in my laravel config folder. Also, I set default => env('DB_CONNECTION', 'sqlsrv')
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.
This question already has answers here:
MySQL connection not working: 2002 No such file or directory
(23 answers)
Closed 7 years ago.
Pulled a perfectly working laravel project from a git into a mac running MAMP. Project ran perfectly on a linux machine.
composer install
php artisan migrate, got the following error:
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
NB:
php -v is 5.5 and mysql -v is 5.5 from the terminal
Here is part of my config/database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'essays',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I tried replacing localhost with 127.0.0.1 with no avail. Kindly help..
Edit:
I added these three lines in my php.ini
mysql.default_socket = /var/run/mysqld/mysqld.sock
mysqli.default_socket = /var/run/mysqld/mysqld.sock
pdo_mysql.default_socket = /var/run/mysqld/mysqld.sock
I also added this symlink:
sudo mkdir /var/mysql
cd /var/mysql && sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
But that didnt solve. I also pulled a fresh new laravel project from git and ran into the same error after composer install then php artisan migrate
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
The mac version is 10.7.4
If you are using MAMP be sure to add the unix_socket key with a value of the path that the mysql.sock resides in MAMP.
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => 'database',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Do not assume your unix_socket which would be different from one to another, try to find it.
First of all, get your unix_socket location.
$ mysql -uroot -p
Enter your mysql password and login your mysql server from command line.
mysql> show variables like '%sock%';
+---------------+---------------------------------------+
| Variable_name | Value |
+---------------+---------------------------------------+
| socket | /opt/local/var/run/mysql5/mysqld.sock |
+---------------+---------------------------------------+
Your unix_soket could be diffrent.
Then you got 2 solution to solve your issue:
(1) Change your config/database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'essays',
'username' => 'root',
'password' => 'root',
'unix_socket' => '/opt/local/var/run/mysql5/mysqld.sock', //Your sock got from above
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
(2) Change your php.ini, find your php.ini file from
<? phpinfo();
You maybe install many php with different version, so please don't assume your php.ini file location, get it from your 'phpinfo';
Change your php.ini:
mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock
pdo_mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
Then restart your apache or php-fpm.
Had the same problem, but it's working for me now.
If anybody is still having problems, try this:
Make sure your bootstrap/start.php contains your actual hostname, not the name of your virtual host. Enter hostname in the terminal to get your hostname. As it's an array I believe you can enter both your hostname and the name(s) of your virtual host(s).
Replace "localhost" with "127.0.0.1".
If you are using XAMPP, the solution is:
'mysql' => array(
'driver' => 'mysql',
'unix_socket' => '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock',
'host' => 'localhost'
)
This works for me in Laravel 5.0, change the DB_HOST=127.0.0.1:33060 in .env file.
Others answers don't work...
If you are using Laravel 5.1.11 version + MAC + MAMPP
you have to add "Unix_socket " in file "yourapp"/app/config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Unix_socket param was added to above mysql config drive.
For Laravel 5.0+ change localhost to 127.0.0.1 in your .env file as well before you go playing around with Unix Sockets etc - this worked for me.
Noobs beware: For anyone using Laravel 5 and using older learning material be aware that there was quite a marked shift in folder structure from previous versions though this seems to be for the better- check out this article https://mattstauffer.co/blog/laravel-5.0-directory-structure-and-namespace
Another solution is to add the port number in the host key. In this case MAMP uses the 8889 by default:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost:8889',
'database' => 'essays',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),