SQLServer Connection

Hello,
Please, could someone help me to connect my CakePHP 4.0.5 with a SQL Server 2018?
I am completely new with CakePHP and I confess that I am lost.

Environment:

  • CakePHP 4.0.5
  • SQL Server 2018
  • XAMP (Apache + PHP7.4.4)

Message error that I am getting:
“CakePHP is NOT able to connect to the database.
Connection to Sqlserver could not be established: SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53].”

Connection code:

	    'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Sqlserver',
            'persistent' => false,
            'host' => 'MYSERVER:1433/MSSQLSERVER',
            'username' => 'sa',
            'password' => 'abcde',
            'database' => 'myDB',
            'prefix' => '',
            'encoding' => PDO::SQLSRV_ENCODING_UTF8,
            'timezone' => ‘UTC’,
            'flags' => [],
            'cacheMetadata' => true,
            'log' => false     
        ],

Thank you very much.

Best regards,
Dante

Make sure you have your database configured properly, or I would suggest trying another database system.

Here is the info about database support with CakePHP: https://book.cakephp.org/4/en/orm/database-basics.html#supported-databases it mentiones support for SQL Server, but it might not have great support.

MySQL and MariaDB work really well, but otherwise I have no expirence with SQL Server.

These things are almost always firewalls or permissions issues on the database server (e.g. not allowing connections from the system your PHP code is running on).

Thanks for the advice.
I tested with MySQL and it works fine.
About the SQLServer, we have an old system and I need to connect to a DB that we are using already.

Hi @Zuluru,
thank you.

I think so too. It is a server here in my company. I will contact the support center.

Issue solved.

'default' => [
    'className' => 'Cake\Database\Connection',
    'driver' => 'Cake\Database\Driver\Sqlserver',
    'persistent' => false,
    'host' => 'MYSERVER',
    'port' => 1433,
    'username' => 'sa',
    'password' => '123456',
    'database' => 'MYDB',
    'prefix' => '',
    'encoding' => PDO::SQLSRV_ENCODING_UTF8,
    'flags' => [],
    'cacheMetadata' => true,
    'log' => false  
],