Laravel 5.2 oracle database PDOException - php

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

Related

GAE Laravel connect to external SQL Server get error

I use Laravel + SQL Server deploy to GAE, when connect to external SQL Server, I get error
could not find driver
but in my local environment it works, so hope someone can help.
.env
DB_CONNECTION=sqlsrv
database.php
'sqlsrv' =>
['driver' => 'sqlsrv',
'host' => 'host',
'port' => '1401',
'database' => 'database',
'username' => 'username',
'password' => '',
'prefix' => '',]
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
Driver:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'db'),
'port' => env('DB_PORT', 'port'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', 'pass'),
'charset' => 'utf8',
'prefix' => '',
]

Laravel 5.0 Auth uses Homestead instead of .env DB

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.

Laravel use old DB connection

I'm developing a project in laravel and I have to change the db connection.
I add a new connection and set this like default but when I run the app it uses the old connection and I don't understand why.
I'm not using .env just setting config/database.php.
'default' => env('DB_CONNECTION', 'DB2'),
'connections' => [
'DB2' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'IP'),
'database' => env('DB_DATABASE', 'DB2'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', '*****'),
'charset' => 'utf8',
'prefix' => '',
],
'DB1' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '2222'),
'database' => env('DB_DATABASE', 'DB1'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', '****'),
'charset' => 'utf8',
'prefix' => '',
],
],
How can I solve this?
Thank you
you just clear the config cache using the following commands:
php artisan config:clear
php artisan config:cache

Laravel switch mysql to mongodb

After completed my project I deiced switch mysql to mongodb. I am using Laravel 5.4 version and for mongodb use jenssegers. For laravel mongdb installation I follow jenssegers installation documentations and installation successfully completed. But after installation I go for migration and use command php artisan migrate. When I use this command shown error InvalidArgumentException in /vendor/mongodb/mongodb/src/Database.php line 83: $databaseName is invalid:
My database.php
'default' => env('DB_CONNECTION', 'mongodb'),
'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', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'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',
'sslmode' => 'prefer',
],
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE', 'project_db'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'options' => [
'database' => 'admin' // sets the authentication database required by mongo 3
]
],
],
My .env
DB_CONNECTION=mongodb
DB_HOST=localhost
DB_PORT=27017
DB_DATABASE=admin
DB_USERNAME=
DB_PASSWORD=
And I also facing one more problem if whatever I change in .env and database.php like if I change port 27017 to 3303 but on browser shows 27017. I cleared cache and all. I don't know what is problem in my code.
These are the steps Envoyer (made by Laravel's creator) takes to deploy an app on production -- I've annotated them below:
# Clear the old boostrap/cache/compiled.php
php artisan clear-compiled
# Recreate boostrap/cache/compiled.php
php artisan optimize
# Migrate any database changes
php artisan migrate

connection laravel and oracle by yajra

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

Categories