TCP Provider connection refused - Laravel 6 and SQL Server (Microsoft) and Laragon - php

I'm currently on a fresh install of Laravel 6 and trying to connect it to my Microsoft SQL Server, and I am serving it locally using Laragon.
I have downloaded the ODBC driver for SQL Server.
My database.php file contains:
'default' => env('DB_CONNECTION', 'sqlsrv'),
...
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
'odbc' => true, // I added this line
'odbc_datasource_name' => '{SQL Server}', // I added this line
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
And my .env contains the valid login credentials. To test that I can connect to the DB, I did a check in welcome.blade.php:
#php
if (DB::connection()->getDatabaseName())
{
echo "connected successfully to database ".DB::connection()->getDatabaseName();
}
#endphp
Which echos onto my page as:
connected successfully to database testDatabase
I have gone into Tinker to see if I can get a Collection of all Employees from my model, i.e. Carer.php:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Carer extends Model
{
protected $table = "dbo.carer";
protected $primaryKey = 'CarerID';
}
...
$carer = App\Carer::all();
Which returns:
Illuminate/Database/QueryException with message 'could not find driver (SQL: select * from [dbo].[carer])'
Does this mean my check for connecting to the database is faulty if I cannot find a driver when attempting to retrieve model data? Do I have to do something specific in Laragon to get it to work for SQL Server?
Thank you.
UPDATE: Following the instructions from here and here, I have managed to add the PDO drivers to my php.ini file and get it running with Laragon. When I print out phpinfo() I can now see the sql servers.
The error I am now getting is:
Illuminate/Database/QueryException with message 'SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.
(SQL: select top 1 * from [dbo].[carer])'

Answering this in case anybody else gets stuck on the same point.
My Microsoft SQL Server didn't have connection over TCP/IP enabled.
You want to:
Open SQL Server Configuration Manager
Under SQL Server Network Configuration, select Protocols for MSSQLSERVER
Right click on TCP/IP and click Enable
Restart SQL Server (MSSQLSERVER)
Source

Related

Connect Laravel Framework 5.6.27 and PHP 7.1.9 to SQL Server 2014

I'm coding an app using Laravel 5.6.27, PHP 7.1.9 and SQL Server 2014 and I tried several solutions found online (most are lower in the version I am using) including from this site.
Basically here's what I have done so far,
Configured .env to this:
DB_CONNECTION=sqlsrv
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydatabasename
DB_USERNAME=sa
DB_PASSWORD=mypassword
database.php to this:
line 16:
'default' => env('DB_CONNECTION', 'sqlsrv'),
line 70:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
I also tried replacing those entries in line 70 with the actual credentials,still unsuccessful.
I also tried this extension both from SQLSRV52.EXE and SQLSRV43.EXE and from unofficial releases.
extension=php_sqlsrv_71_ts_x64.dll
extension=php_pdo_sqlsrv_71_ts_x64.dll
extension=php_pdo_sqlsrv_71_ts.dll
extension=php_sqlsrv_71_ts.dll
extension=php_pdo_sqlsrv_71_ts_x86.dll
extension=php_sqlsrv_71_nts_x86.dll
extension=php_pdo_sqlsrv_7_ts_x86.dll
extension=php_pdo_sqlsrv_71_ts_x64.dll
Here's the error i encountered when i run php artisan migrate:
Illuminate\Database\QueryException : could not find driver (SQL: select * from sysobjects where type = 'U' and name = migrations)
and when i run DB::connection()->getPdo();
$ php artisan tinker
Psy Shell v0.9.6 (PHP 7.1.9 — cli) by Justin Hileman
>>> DB::connection()->getPdo();
PDOException with message 'could not find driver'
>>>
Additionally, I'm not sure if with this error in login page "SQLSTATE[HY000]: [Microsoft][ODBC Driver 17 for SQL Server]Protocol error in TDS stream (SQL: select top 1 * from [users] where [email] = test1234#gmail.com)" means it was able to find the driver thru web login and just php artisan that can find the driver.
I hope someone can enlighten me on this.
Thank you very much!
Besides Stefan said, also use a view where you just put phpinfo().
This is just to check if you have installed pdo extension for sql server.
It should look like that:
If not, you should install that extension.
And also pay attention on the others parameters in .env file like DB_DATABASE, DB_USERNAME, etc because they take precedence over the values set in database.php
In .env file, you have the port 3306 (mysql). Should be 1433 for Sql.

pdo_oci_handle_factory: Error while trying to retrieve text for error ORA-01804

I'm using Laravel 5.5, php 7.1.9, and oracle 10g
i don't know if i'm connected to the database or not and if yes, is the problem in my code ?
PDOException SQLSTATE[HY000]: pdo_oci_handle_factory: Error while
trying to retrieve text for error ORA-01804
(ext\pdo_oci\oci_driver.c:640)
oracledb.php
return [
'oracle' => [
'driver' => 'pdo',
'tns' => env('DB_TNS', 'XE'),
'host' => env('DB_HOST', 'GREEN-PC'),
'port' => env('DB_PORT', '1521'),
'database' => env('DB_DATABASE', 'XE'),
'username' => env('DB_USERNAME', 'esprit'),
'password' => env('DB_PASSWORD', 'esprit'),
'charset' => '',
'prefix' => '',
'quoting' => false,
],
];
in my controller
public function show()
{
$res = DB::table('esp_etudiant')
->where('id_et','1630242')
->get();
print_r($res);
}
First, try connecting as SYSDBA.
$ sqlplus / as sysdba
There are several causes for the ORA-01804 error:
Check to make sure the following paths are set correctly in your environment:
$LD_LIBRARY_PATH
$ORACLE_HOME
$NLS_LANG
Your oracle client may be missing some timezone dat files in the $ORACLE_HOME directory. You should have a separate ORACLE_HOME for each release of Oracle. If this is the case, then :
The first thing to do is to check if ORA_TZFILE is set and if it is,
remove it and restart the database and listener. Oracle will then try
to load the $ORACLE_HOME/oracore/zoneinfo/timezlrg.dat file.
If for some reason the file that Oracle wants to use is not available
then this is the cause of the problem.
If the file is present then an alternative reason for the error could
be that Oracle cannot load the file because of permission problems.
If all above is correct then it might be a .dat file that is corrupt.
Check that the permissions are set to allow reads (chmod 444) for the files in the OCCI library.

Oci8Exception in Oci8.php line 466

Attempting to connect to an Oracle database with yajra/laravel-oci8, below is the configuration. Note that I've also installed the instant client 11g corresponding to the bit version of Windows Server. I've ensured that the 11g ext is enabled in the php.ini.
Spent 4 days on this now, does anybody have any idea what's going on?
I don't even get an error message, just a stack dump which is attached.
'oracle' => [
'driver' => 'oracle',
'tns' => 'LISTENER',
'host' => '192.168.39.73',
'port' => env('DB_PORT', '1521'),
'database' => 'QORA',
'username' => 'ETEST',
'password' => 'ETEST',
'charset' => env('DB_CHARSET', 'AL32UTF8'),
'prefix' => env('DB_PREFIX', ''),
'prefix_schema' => env('DB_SCHEMA_PREFIX', ''),
],
Your error messages are showing you are trying to connect on port 3306, which is the standard MySQL port. According to your config, you're looking at the DB_PORT value from the .env file, with a backup of 1521 if that doesn't exist.
My guess is that your .env file has the following line:
DB_PORT=3306
You either need to comment or remove that line, or change 3306 to 1521.

Laravel 5.1 Forge - SQLSTATE[HY000] [1045] Access denied for user ''#'localhost' (using password: NO)

Ive just built my new app in Laravel 5.1 and im trying to push it live. When i try to composer install i am getting this error.
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user ''#'localhost' (using password: NO)
Script php artisan clear-compiled handling the post-install-cmd event returned with an error
[RuntimeException]
Error Output:
I am using a environment file on both local and production so i have no idea whats going on. Any ideas?
Its like my environment file is not getting picked up on forge.....
config/datasbase.php
<?php
return [
/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/
'fetch' => PDO::FETCH_CLASS,
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'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', ''),
'charset' => 'utf8',
'prefix' => '',
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'cluster' => false,
'default' => [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
],
],
];
The reason this is happening is because forge is running the post install command on your project and your are probably accessing the database in one of your service providers to for may be a a variable you want to attach to your views, try commenting the code in the service provider, install the repository and then push the code up again it should work fine
The reason this was happening is because i was using the 'Install Repo' functionality that forge provides to install my full project. Now because there was no environment set on the server it was failing upon install.
To get around it, i had to hardcode the production database credentials, install the repo then create the env file. Then once this was done remove the hardcoded credentials (not great i know).
It seems setting the .env before the install doesn't work either. So you wouldn't run into this sort of issue if you had your repo installed on a server from the beginning of your build.
But my project is now live and running correctly. Thanks for the replies.
try this
1
in app/database.php
Replace localhost with 127.0.0.1
'host'=> env('DB_HOST', 'localhost') -->'host' => env('DB_HOST', '127.0.0.1')
Also, in .env
DB_HOST=localhost --> DB_HOST=127.0.0.1
2
Try specify environment
php artisan migrate --env=local
3
Check to see if the MySQL is running by run
mysqladmin -u homestead -p status Enter password: secret
I got
Uptime: 21281 Threads: 3 Questions: 274 Slow queries: 0 Opens: 327 Flush tables: 1 Open tables: 80 Queries per second avg: 0.012
Which mean it's running.
4
Check MySQL UNIX Socket
5
make sure that your .env file looks something like this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=YOURAPPKEY
DB_HOST=localhost
DB_DATABASE=YOURDBNAME
DB_USERNAME=YOURPHPMYADMINUSERNAME
DB_PASSWORD=YOURPHPMYADMINPASS
6
try changing localhost into 127.0.0.1 in .env DB_HOST or try add your mysql port
Make sure MySQL user has all accessing privileges for given ip while connecting the MySQL. For further reference please go through the below link.
http://tech2smooth.blogspot.in/2014/09/create-mysql-user-and-grant-permission.html
It's hard to say anything for sure without seeing the .env file, but it looks like it's picking up the username from somewhere - the default is 'forge' and yet the error message has the username as an empty string - ''#localhost.
Check your env file, make sure there are no spaces after the = and that the variable names match the ones in the database config. I've also had issues where I needed to wrap passwords and other values that had special characters in ''. Finally, remember that case matters - I've seen problems where everything worked locally and failed on the dev server because someone had changed the case of a variable. My mac didn't care, but the ubuntu server did.

Laravel: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

I am using schema builder to create a Mysql table. I am using Ubuntu 14.04.
My connection for Mysql in config/database.php is :
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'firstapp'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
And Code for creating table with schema builder on routes.php
Route::get('/', function () {
Schema::create('art', function($newtable)
{
$newtable->increments('id');
$newtable->string('artists');
$newtable->string('title',500);
$newtable->text('discription');
$newtable->date('created');
$newtable->date('exhibition_date');
$newtable->timestamps();
});
return view('welcome');
});
Thanks
As far a as i know , you must create a migration file using
php artisan migrate:make yourtable
Then yo must go to database folder you will find a new migration file created , then you must open it , and fill it with your schema , once you finish , then run migration
php artisan migrate
And that's all you will see your new table created.
Migrations laravel 5
First i was using xampp mysql and this was also started /etc/init.d/mysql from terminal, Since i am using Ubuntu 14.04.
I solved the problem which i posted above then another problem came up Saying SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES).
I changed the .env file which is placed in the root directory of laravel and i changed the Database Name name and password which i was using for mysql.
It solved that problem too and i am up and running.

Categories