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' => '',
]
Related
I have 2 projects (A and B), the project A using Laravel 5.4 and connecting in a database instance from mssql (this database is to my development environment). The project B use Laravel 5.7 and cannot connect in the same instance, I get this return:
"SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired
But both projects can connect in production without problems. I use the same database confs for project A and B.
I running a docker container and the Dockerfile is the same for both projects. I can't undestand why in one works, but in another no.
I'm using php 7.1
Production Conf:
'database_test' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'sqlsrv.xxxxx.com.br'),
'database' => env('DB_DATABASE', 'database'),
'username' => env('DB_USERNAME', 'user_database'),
'password' => env('DB_PASSWORD', 'user_password'),
'charset' => 'utf8',
'prefix' => '',
'options' => [
],
Development Conf:
'database_test' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', '99.000.000.99\MBC03'),
'database' => env('DB_DATABASE', 'database'),
'username' => env('DB_USERNAME', 'user_database'),
'password' => env('DB_PASSWORD', 'user_password'),
'charset' => 'utf8',
'prefix' => '',
'options' => [
],
],
I am using Laravel 5.6, and trying to connect with MS SQL Server 2008 R2, all running on local machine. I have a test database named "ItemMaster", which is working fine with my C#.Net application.
When I try to connect same database from Laravel, I am getting this error:
SQLSTATE[08001]: [Microsoft][ODBC Driver 11 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it. (SQL: select * from ITEM_CATEGORY)
Can anybody suggest how to fix this.
In config/database.php, I have setup sqlsrv driver as follows:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'MY-PC\MYSQL2008R2'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'ITEMMASTER'),
'username' => env('DB_USERNAME', 'myuser'),
'password' => env('DB_PASSWORD', 'mypassword'),
'charset' => 'utf8',
'prefix' => '',
],
Getting error on this line inside my controller:
$items = DB::connection('sqlsrv')->select('select * from ITEM_CATEGORY');
I installed Microsoft Drivers 4.3 for PHP for SQL Server and copied file php_pdo_sqlsrv_71_ts_x86.dll to php/ext folder.
I find solution for this problem, sharing might help someone else making same mistake.
Actually the mistake is how I defined SQL Connection parameters in config/database.php
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'MY-PC\MYSQL2008R2'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'ITEMMASTER'),
'username' => env('DB_USERNAME', 'myuser'),
'password' => env('DB_PASSWORD', 'mypassword'),
'charset' => 'utf8',
'prefix' => '',
],
In this code segment, I actually defined my parameters as second parameter to env() which (be-definition) is not the real value but will be used as default value if that specific key is not found in .env file.
You can read more about Environment configuration here
So the final code segment should be like this:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => 'MY-PC\MYSQL2008R2',
'port' => '1433',
'database' => 'ITEMMASTER',
'username' => 'myuser',
'password' => 'mypassword',
'charset' => 'utf8',
'prefix' => '',
],
Or another alternative may be to define these parameters in .env file, in the root directory of your application .
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
I'm trying to install my homestead with sql server.
i installed sudo apt-get install php7.0-sybase
i configure my .env
config/database.php
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'utp'),
'username' => env('DB_USERNAME', 'sa'),
'password' => env('DB_PASSWORD', 'secret123'),
'prefix' => '',
],
.env
DB_CONNECTION=sqlsrv
DB_HOST=localhost
DB_PORT=1433
DB_DATABASE=utp
DB_USERNAME=sa
DB_PASSWORD=secret123
display this error
http://imgur.com/a/O3TB1