I am configuring my postgresql driver in Laravel 5.4 for deployment to Heroku. Here is my config/database.php, the default is already set to pgsql
'pgsql' => [
'driver' => 'pgsql',
'host' => parse_url(getenv("DATABASE_URL"))['host'],
'database' => substr(parse_url(getenv("DATABASE_URL"))['path'], 1),
'username' => parse_url(getenv("DATABASE_URL")['username']),
'password' => parse_url(getenv("DATABASE_URL")['password']),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
When I commit I see this warning
PHP Warning: Illegal string offset 'username' in app/config/database.php on line 62
When run heroku run php artisan serveI am getting an error
[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: PDO::__construct() expects parameter 2 to be string, array given
Here is my .env
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=forge
DB_USERNAME=postgres
DB_PASSWORD=
Your configuration array should look like the following if you want to get correct data from the .env provided.
'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',
]
I found the answer in this site. It caters also mysql, and sqlite, please read
https://mattstauffer.co/blog/installing-a-laravel-app-on-heroku
Related
I've installed pgsql and set up my Laravel config/database.php as follows:
'connection_name' => [
'driver' => 'pgsql',
'host' => env('DB_HOST_2', '127.0.0.1'),
'port' => env('DB_PORT_2', '3306'),
'database' => env('DB_DATABASE_2'),
'username' => env('DB_USERNAME_2'),
'password' => env('DB_PASSWORD_2', ''),
'sslmode' => env('DB_SSLMODE_2'),
'charset' => 'utf8',
'prefix' => '',
'options' => [
'sslcert' => '/some/special/path.crt',
],
'schema' => 'public',
],
'connection_name' is located in the 'connections' section of database.php.
In artisan tinker I get the following error because it's still looking in the default location for the SSL certificate. I cannot get it to look in the right location for the cert.
>>> use Illuminate\Support\Facades\DB;
>>> DB::connection('connection_name')->getPdo()
Doctrine\DBAL\Driver\PDOException with message 'SQLSTATE[08006] [7] root certificate file "/home/wes/.postgresql/root.crt" does not exist
Either provide the file or change sslmode to disable server certificate verification.'
The root cert is set by "sslrootcert". This is the certificate that signed the server's cert.
"sslcert" sets the client cert. That is something different.
This is a pretty old question, but I ran into this issue today. My solution was a combination of jjanes answer and comment. I had to set the variable at a higher level and also change to "sslrootcert"
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'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' => '',
'prefix_indexes' => true,
'search_path' => 'public',
'sslmode' => env('SSL_MODE'), <-- this says "verify-ca"
'sslrootcert' => env('PGSQL_SSL_CA') <-- this is fullpath
],
This worked when I used php artisan migrate on my PGSQL managed database on Digital Ocean.
I've setup Laravel 5.0 (that's a requirement) and set it up to use remote MySQL DB. All migrations and data interactions pass OK, but when trying to use Auth login POST, it fails with PDOException in Connector.php line 47:
SQLSTATE[HY000] [2002] No such file or directory, mentioning " PDO->__construct('mysql:host=localhost;dbname=homestead', 'homestead', 'secret', array('0', '2', '0', false, false))"
WHERE did it take that homestead DSN? Why does it skip the database.php config and .env config? If I try to add to .env some socket info (well it should not count here, right?) the socket path passes to the mentioned PDOException call stack, but hostname, login etc. NOT!
Confused. What am I doing wrong?
UPD
Here's the .env:
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
DB_HOST=mysql.someremteohosting.net
DB_DATABASE=mydb
DB_USERNAME=myuser
DB_PASSWORD=mysuperpassword
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
And here's database.php:
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default' => 'mysql',
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path().'/database.sqlite',
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'prefix' => '',
],
],
'migrations' => 'migrations',
],
];
Again, all migrations work. I can create, save and fetch objects in tinker without any problem. The only reference to homestead is in .env.example file.
Not sure what exactly was wrong here. The only place where I found 'homestead' in the app code was in .env.example. I deleted it an ran composer dump-autoload. After that it worked. Still surprised about laravel lurking into .example config without any reason.
I almost gave up, before there is no problem but after I reinstall the oracle why laravel can't connect.
This error as I can when running the migrate:
c:\xampp\htdocs\tester>php artisan migrate
[Yajra\Pdo\Oci8\Exceptions\Oci8Exception]
ORA-24315: illegal attribute type
file .env ->
DB_CONNECTION=oracle
DB_HOST=127.0.0.1
DB_PORT=1521
DB_DATABASE=corsys
DB_USERNAME=tester
DB_PASSWORD=orcl
oracle.php in the folder config ->
<?php
return [
'oracle' => [
'driver' => 'oracle',
'tns' => env('DB_TNS', ''),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '1521'),
'database' => env('DB_DATABASE', 'corsys'),
'username' => env('DB_USERNAME', 'tester'),
'password' => env('DB_PASSWORD', 'orcl'),
'charset' => env('DB_CHARSET', 'AL32UTF8'),
'prefix' => env('DB_PREFIX', ''),
'prefix_schema' => env('DB_SCHEMA_PREFIX', ''),
],
];
please help me :(
You need to enable your oracle driver for PHP to be able to access your oracle database.
Related answer here:
https://stackoverflow.com/a/26213384/1739852
I am working on xamp, using laravel 5.2 and trying to connect oracle database
here I want to get values in tinker:
DB::table('dept')->get();
with this error:
PDOException with message 'could not find driver'
my .env file
DB_CONNECTION=sqlsrv
DB_HOST=localhost
DB_PORT=1521
DB_DATABASE=Mydb
DB_USERNAME=db_username
DB_PASSWORD=password
my database.php
'default' => env('DB_CONNECTION', 'sqlsrv'),
...
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'Mydb'),
'username' => env('DB_USERNAME', 'db_username'),
'password' => env('DB_PASSWORD', 'password'),
'charset' => 'utf8',
'prefix' => '',
],
Install Oracle client in your machine: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
Install/enable Oracle for PHP. That will depend on your operation system. In windows, I believe you only need to enable on your php.ini, extension=pdo_oci.dll. In linux, you need to install, with apt get or similar in your distro, or recompile PHP with instructions on this page: http://php.net/manual/en/ref.pdo-oci.php
Use this library in your Laravel project: https://github.com/yajra/laravel-oci8
In config/database.php:
'default' => env('DB_CONNECTION', 'my_connection'),
'connections' => [
'my_connection' => [
'driver' => 'oracle',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1521'),
'service_name' => env('DB_SERVICE_NAME', ''),
'database' => env('DB_DATABASE', ''),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'options' => [
PDO::ATTR_PERSISTENT => true
],
],
In your .env:
DB_CONNECTION=my_connection
DB_HOST=111.111.111.111
DB_SERVICE_NAME=service
DB_DATABASE=db
DB_USERNAME=user
DB_PASSWORD=pass
It's been around 5-6 hours since I've been trying to use database in laravel 5.
I've gone through of videos and it confused me a lot.
I have created the model and migration but when i try to migrate it gives me an
[ PDOException ] Driver not found
I've made numerous changes to .env and database.php but nothing works.
I am using laravel 5 with xampp server.
Kindly help
Thank you
.env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=zZfvju3BKjxmLKbl5gsVJ3ymkIvHbGNq
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=medicaldb
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
database.php file
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'medicaldb'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
],
'migrations' => 'migrations',
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
Finally, at last! it worked!!
In php.ini file:
(semi-colon) ; works as a single-line comment in php.ini file.
(semi-colon) was added at the beginning of the line - which disables pdo mysql driver.
I just needed to remove the semi-colon(;) to enable mysql, from the beginning of the line.
Same problem, ubuntu 17.10, Laravel 5.6
It is the issue normally come when you upgrade you php version I get the same issues in my lammp stack while i update from php 7 to 7.1 I get Solve by following command
Open Terminal
sudo apt install php7.1-pdo php7.1-mysql
Have fun with Code
Are you sure you have mysql intalled? also, please check pdo_mysql module is enabled. use phpinfo();