Connecting to MSSQL Server 2005 using PHP PDO - php

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.

Related

Using ODBC Driver 13 instead of ODBC Driver 11 to Connect to SQL Server 2008 R2

I am trying to connect to my MS SQL Server (2008 R2) with php and xampp. Upon running the code I got this error:
Connection could not be established.Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -49
[code] => -49
[2] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
[message] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server 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
)
)
So, I decided to try to install the ODBC Driver 11. I could not install the driver on Windows 10 because it's not supported so I downloaded ODBC Driver 13 and it still did not work. Is there a way I can reconfigure ODBC Driver 13 so it will work in replace of ODBC Driver 11? If there is anything else I can provide that would be useful let me know. I cannot use MySQL for this, nor can I update SQL Server.
PHP SQL Server Couldn't connect
PHP 5.5 and MSSQL driver: Installing ODBC Driver 11 in Windows Server 2012 R2
To make an addition, make sure you installed the correct version (32-bit vs 64 bit) of ODBC!
Know which version your system runs: your SQL server might be a different version.
Even if these questions don't solve it directly, they might contain useful information for your situation.
Refer to these questions; I think you should be able to find a solution.
The DLL file of ODBC might need to be copied under your working directory of PHP in addition to being installed.
I see that being a common problem with JDBC at least.
Good luck!

Can't connect to SQL Server from PHP

I use XAMPP. I need to establish connection from PHP code to my MS SQL Server. Therefore, I installed the sqlsrv driver from here. According to phpinfo() it's being loaded properly:
I get this error message:
Connection could not be established. Array ( [0] => Array ( [0] =>
IMSSP [SQLSTATE] => IMSSP => -49 [code] => -49 => This
extension requires the Microsoft ODBC Driver 11 for SQL Server. Access
the following URL to download the ODBC Driver 11 for SQL Server for
x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This
extension requires the Microsoft ODBC Driver 11 for SQL Server. Access
the following URL to download the ODBC Driver 11 for SQL Server for
x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) => Array (
[0] => IM002 [SQLSTATE] => IM002 => 0 [code] => 0 =>
[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 ) )
The links point to x86 client, but I can only install 64-bit version, which I did so from
https://www.microsoft.com/en-us/download/details.aspx?id=29065
Still I get the same error.
Specs:
OS: Windows Server 2012 64-bit
PHP: 5.6.19
Code is simple as that:
$serverName = "servername";
$connectionInfo = array( "Database"=>"DBname", "UID"=>"username", "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));
}
Now what? Shall I register that installed SQL Native Client in any of the PHP/Apache conf files?
According to this blog, Microsoft's SQL Server 2012 Feature Pack does not contain ODBC Driver 11 for SQL Server; which is required for sqlsrv extensions 3.1 and above.
ODBC Driver 11 Download page
I had the same problem...
check which version of php you use by using phpinfo() then download the extensions related to your version of php. Then also go to your php.ini file and add those file like so
extension=<extension>.dll
Then one vital step I was always missing and was stressing me is that you need to download the driver found on the link below... Or else your php script wont connect to your SQL Server .... Download and install this on the machine which actually has SQL Server installed... If it is a remote server this has to be installed on a remotre server... If it is on your local machine this has to be installed on your local machine...
https://www.microsoft.com/en-us/download/details.aspx?id=36434
Can't connect to SQL Server from PHP
Then you should be good to go...

How can i connect PHP 5.5.x or above version to mssql 2008 R2 in wamp?

How can i connect PHP 5.5.x or above version to mssql 2008 R2 in wamp?
Versions :
php : 5.5
Compiler : MSVC11
Architecture : x86
Tread safety : enabled
I tried with following step :
1. Tried connecting with sqlsrv_connect()
Example code below(test-connect.php) :
<?php
$serverName = "192.168.1.5";
$connectionInfo = array( "Database"=>"testDB", "UID"=>"sa", "PWD"=>"sa123");
$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));
}
?>
When I run file test-connect.php, its throwing the following error :
**"Fatal error: Call to undefined function sqlsrv_connect()"**
I tried putting following two DLL file to PHP ext folder
a) php_pdo_sqlsrv_55_nts.dll
b) php_sqlsrv_55_nts.dll
And updated php.ini with the following extensions
extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll
Restarted all services
Still it throw below given error :-
**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 ) )**
Can anyone help me with fixing this? Is this the problem with versions of Apache/PHP ?
Look here :
http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-the-sql-server-driver-for-php
Basicly you need to install library which url is in your error desc and put to php.ini this library, somethin like this:
Extension=php_sqlsrv.dll

issue integrating php with sqlserver

It's my first time integrating php with SQL Server. The SQL server in context is located on another physical computer on the same LAN. I'm using the configuration explained below:
php: version 5.5
SQL Server: 2005 Express
php drivers: sqlsrv 3.2
thread safety: disabled
I'm being faced with the error below:
Connection could not be established. 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 ) ).
The code being used follows below:
<?php
$serverName = "TESTSERV\SQLEXPRESS"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbname", "UID"=>"username", "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));
}
?>
Can anyone guide me on what needs to be done here in order to successfully connect to the database?
Microsoft SQL Server Driver for PHP requires installation of Microsoft SQL Server 2012 Native Client as you can read in error message. Only downloading of extension dll is not enough. You can read more in official System Requirements (Microsoft Drivers for PHP for SQL Server).
Versions 3.2 and 3.1 require Microsoft ODBC Driver 11 (or higher) for SQL Server. To download the Microsoft ODBC Driver 11 for PHP for SQL Server, see Microsoft ODBC Driver 11 for SQL Server.
If you are using the SQLSRV driver, sqlsrv_client_info will return information about which version of SQL Server Native Client is being used by the Microsoft Drivers for PHP for SQL Server. If you are using the PDO_SQLSRV driver, you can use PDO::getAttribute to discover the version.
https://www.microsoft.com/en-us/download/details.aspx?id=36434
Download, install and try to refresh your testing page.

Can anyone decipher an error message I get when trying to store form data on MS SQL using php?

I attempted to connect to an Microsoft SQL database and store html form data in it using php but was unable to.
At first I attempted using the mssql syntax but realized that it was abandoned past 5.2 (I'm running 5.3). Then I attempted to connect using the sqlsrv syntax but that required a driver and editing the php.ini file -- which I did only to receive this error message pertaining to the MS SQL Native Client:
> Connection COULD NOT be establishedArray ( [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 ) )
A phpinfo file shows that sqlsrv is installed and I've deleted and reinstalled the drivers and native client twice already to no avail..........
Here is the stack:
Windows 2003 server
IIS 6 web host
local install of MS SQL 2008 (previously was attempting to connect to a remote MS SQL 2014 database
PHP version 3.1.3

Categories