0

I configured my localhost (WAMP) and now I can connect to another MS SQL server using this code.

<?php
$serverName = "<my ip>,14143\SQLEXPRESS";
$connectionInfo = array(
'Database' => 'dbname', 
'UID' => 'user', 
'PWD' => 'pass');
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if($conn){
 echo "Database connection established.<br />";
}else{
 echo "Connection could not be established.<br />";
 die( print_r(sqlsrv_errors(), true));
}

Now I want to go to shared server, but I get this error

http://akasergej-001-site1.btempurl.com/mssql.php

Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 10013 [code] => 10013 [2] => [Microsoft][ODBC Driver 11 for SQL Server]TCP Provider: An attempt was made to access a socket in a way forbidden by its access permissions. [message] => [Microsoft][ODBC Driver 11 for SQL Server]TCP Provider: An attempt was made to access a socket in a way forbidden by its access permissions. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired [message] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 10013 [code] => 10013 [2] => [Microsoft][ODBC Driver 11 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [message] => [Microsoft][ODBC Driver 11 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. ) )

Another question. Is it possible to connect to MS SQL server from linux hosting? Or i strictly need windows server for this?

user3514052
  • 418
  • 4
  • 18
  • `possible to connect to MS SQL server from linux hosting`, yes it is. I've used PDO for this from a centos 6 system. – user3783243 Mar 29 '19 at 15:30
  • Is your PHP and SQL Server on the same computer, or not? The error implies that maybe the socket is set not to accept connections from remote machines, or something. Or possibly from outside certain IP ranges, I don't know. The error is not hugely specific, as you can see. Perhaps you can tell us your network topology. – ADyson Mar 29 '19 at 16:41
  • no it is in another computer. – user3514052 Mar 29 '19 at 19:00
  • You possibly need to enable remote connections to your SQL Server. It's switched off by default in SQL Express (since that's only really intended as a development tool, not a live system). You can google how to do that white easily – ADyson Mar 30 '19 at 22:51
  • Visit https://stackoverflow.com/questions/18632607/how-to-use-php-to-connect-to-sql-server/43692201#43692201 – hassan javaid Jun 07 '22 at 08:08

0 Answers0