SQL Server 2014 Connection string is not valid [87] in php - php

I upgraded from SQL SERVER 2008 from SQL SERVER 2014.
I am already using SQL SERVER 2008 with PHP. After the upgrade from SQL SERVER 2008 to SQL SERVER 2014 it doesn't seem to be working. It's showing the following error:
[Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network
Interfaces: Connection string is not valid [87]
[Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
[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.

change the \ in $server
and first give UID & PWD then Database
$server = "servername\instancename";
$connectionInfo = array( "UID"=>"", "PWD"=>"****", "Database"=>"", );
$conn = sqlsrv_connect( $server, $connectionInfo );
if ($conn === false)
die("<pre>".print_r(sqlsrv_errors(), true));
echo "Successfully connected!";
this will working..

Related

Unable to connect SQL Server from PHP using Windows Authentication

I'm trying to connect to MS-SQL Server from PHP-8.0 (hosting on IIS-10 localhost) using SQL Server Driver for PHP, i.e., SQLSRV-5.9. While connecting from a PHP page, if I use SQL Server Authentication, it's getting connected right away. But while using Windows Authentication, it's throwing an error in the browser saying:
Connection could not be established.
Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456
[code] => 18456 [2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL
Server]Login failed for user 'NT AUTHORITY\IUSR'. [message] =>
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for
user 'NT AUTHORITY\IUSR'. ) [1] => Array ( [0] => 28000 [SQLSTATE] =>
28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 17
for SQL Server][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'.
[message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL
Server]Login failed for user 'NT AUTHORITY\IUSR'. ) )
My environment is Windows 10 Pro, Version 21H2, 64-bit. In my SQL Server, both Windows Authentication and SQL Server Authentication are enabled, and I'm able to connect to the server using both of them through SQL Server Management Studio. So what's stopping my PHP code to connect to the server using Windows Authentication? Both the PHP and SQL Sever are on the same PC. What am I doing wrong? As I'm new in PHP, can you please clarify it with a simple example?
My connect-db.php code follows. Note how I used connection string for both Windows and SQL Server Authentication.
?php
$serverName = "(local)"; // Optionally use port number (1433 by default).
$connectionString = array("Database"=>"TestDB"); // Windows Authentication connection string.
// $connectionString = array("UID"=>"sa","PWD"=>"sa","Database"=>"TestDB"); // SQL Server Authentication connection string.
$conn = sqlsrv_connect($serverName, $connectionString); // Connect to the server.
if($conn === false) {
echo "Connection could not be established.<br/>";
die(print_r(sqlsrv_errors(), true));
} else {
echo "Connection established successfuly.<br/>";
}
sqlsrv_close($conn); // Close connection resources.
?>
Thanks and Regards!

ODB_CONNECT() not working on windows server 2008 R2

I am trying to make ODBC connection from windows server 2008 R2, but it shows me this error:
Warning: odbc_connect(): SQL error: [Microsoft][ODBC SQL Server
Driver][DBNETLIB]SQL Server does not exist or access denied., SQL
state 08001 in SQLConnect in
C:\xampp\apps\wordpress\htdocs\wp-content\themes\Divi\cargo_consignment_tracking.php
on line 30
My php version is 7.0.9
My connection string to connect with the server
$server = 'SERVER_IP_ADDRESS';
user = 'USERNAME';
$pass = 'PASSWORD';
$port = '1433';
$database = 'cargo_web';
//connection string
$connection_string = "DRIVER={SQL Server};SERVER=$server;$port;DATABASE=$database";
$conn = odbc_connect($connection_string,$user,$pass);
Its working on my localhost server, but not on windows server 2008 R2.
My phpinfo() contains ODBC part and I have enabled odbc connection in php.ini with these lines
extension=php_pdo_odbc.dll
extension=php_odbc.dll
Why am I facing this issue on the server ??

Error connecting to MSSQL using PHP

I am receiving an error as below:
PHP Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[08001]: [Microsoft][ODBC Driver 11 for SQL Server]SQL Server
Network Interfaces: Connection string is not valid [87]. '
My codes are as follow:
$this->link = new PDO(
"sqlsrv:server=$this->serverName:$this->port;Database=$this->db",
"$this->uid",
"$this->pwd"
);
I wish someone can enlighten me on what is causing this error. Before that I was using dblib instead of sqlsrv.
"dblib:host=$this->serverName:$this->port;dbname=$this->db"
I am using XAMMP with Apache 2.4.12 and PHP 5.5.24 (they are all x86). I have php_pdo_sqlsrv_55_ts.dll and php_sqlsrv_55_ts.dll. I am also using Microsoft ODBC Driver 11 for SQL Server-x64.
Change it to:
$this->link = new PDO(
"sqlsrv:Server={$this->serverName},{$this->port};Database={$this->db};",
$this->uid,
$this->pwd
);
The default SQL Server port is 1433. Note the curly brackets, they allow for class variables.

Can't Establish connection to MS SQL Server 2008

I have been trying to establish a connection to a SQL Server 2008 but i get a return message saying:
Connection could not be established. Array ( [0] => Array ( [0] =>
08001 [SQLSTATE] => 08001 [1] => -1 [code] => -1 [2] =>
[Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network
Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
[message] => [Microsoft][ODBC Driver 11 for SQL Server]SQL Server
Network Interfaces: Error Locating Server/Instance Specified
[xFFFFFFFF]. ) [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] => -1 [code] => -1 [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. )
My PHP Code:
<?php
$serverName = "SERV002\SQLEXPRESS"; //serverName\instanceName
$connectionInfo = array( "Database"=>"YSHSDB", "UID"=>"sa", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
UPDATE: I have fixed this by installing xampp lite onto my server 2003 running the SQL server however, I would still like to be able to access the SQL server if the web services is running on another machine.
The obvious error here is that your SQL server is not running or is not configured to allow remote connections (I think that is the default for SqlExpress)
You will need to open your Sql Connection Manager and change the settings for TCP connections to make them available for remote connections. You may also have a firewall blocking your Sql Connection somewhere. Make sure port 1433 is exposed in any fire wall.
Open your Server Configuration Manager
Server Configuration Manager
Under SQL Server Network Configuration
Click on Protocols for SQLEXPRESS
Rightclick and access Properties of TCP/IP
Select the IP Addresses Tab
Now configure all the TCP Port(s) to the port you are using in your connection string.

Connecting to MSSQL Server 2005 using PHP PDO

I'm trying to establish a connection with PHP and MS SQL Server 2005. I'm using IIS 8 in Windows 8 and PHP version 5.3.28. I already done my research, I've found MSSQL PHP PDO (http://www.php.net/manual/en/ref.pdo-sqlsrv.connection.php and http://technet.microsoft.com/en-us/library/ff754357(v=sql.105).aspx), downloaded and enabled all of PDO related DLLs I've found from Microsoft website (Microsoft Drivers 3.0 for PHP for SQL Server) and assured they are reflecting in phpinfo().
extension=php_pdo_sqlsrv_52_nts_vc6.dll
extension=php_pdo_sqlsrv_53_nts.dll
extension=php_pdo_sqlsrv_53_nts_vc6.dll
extension=php_pdo_sqlsrv_53_nts_vc9.dll
extension=php_pdo_sqlsrv_54_nts.dll
extension=php_pdo_sqlsrv_54_nts.dll
extension=php_sqlsrv_54_nts.dll
extension=php_sqlsrv_53_ts_vc9.dll
The following links in Stock Over Flow also helped me alot in my dilemma:
Connect to SQL Server through PDO using SQL Server Driver
Error connecting to MSSQL with SQLSrv and PHP 5.4.7
How can I connect to Sql Server from a Mac with PHP PDO?
Connecting to mssql using pdo through php and linux
I'm able to fix the "driver not found" and "connection string is invalid" issues, and here's my current PHP codes:
$db_server = "func.website.com,8787";
//$db_server = "func.website.com:8787\sqlexpress";
$db_database = "db_BreadNButter";
$db_user = "tinapay";
$db_passwd = "p#ssword";
try {
//$db = new PDO ("mssql:host=$db_server;dbname=$db_database;", $db_user, $db_passwd);
$db = new PDO ("sqlsrv:Server=$db_server;Database=$db_database;", $db_user, $db_passwd);
} catch(PDOException $exception) {
die("Unable to open database.<br>Error message:<br><br>$exception.");
}
I think (fingers-crossed) that I already established a connection to MSSQL DBase, but I'm getting the error below:
exception 'PDOException' with message 'SQLSTATE[08001]:
[Microsoft][SQL Server Native Client 11.0]TCP Provider: Timeout error [258].
' in C:\inetpub\wwwroot\breadnbutter\class.connection.php:12 Stack trace: #0
C:\inetpub\wwwroot\breadnbutter\class.connection.php(12):
PDO->__construct('sqlsrv:Server=f...', 'tinapay', 'p#ssword') #1 {main}.
Can anyone enlighten me on why am I getting timeout errors and how can I fix this?
The port should be func.website.com:8787. You have a typo with the comma.
how to connect sqlsrv 2008 in php 5.4.4
erro is:
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -49
[code] => -49
[2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
[message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
)
[1] => Array
(
[0] => IM002
[SQLSTATE] => IM002
[1] => 0
[code] => 0
[2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
[message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
)
)
I'm still having problems with this, but I'm able to convince my boss to use asp instead of PHP. thanks a lot for those who helped me out.

Categories