0

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:

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?

9
  • from my experience trying to connect to MSSQL I ended up using php_odbc - if you don't have to use PDO maybe try that Commented Mar 28, 2014 at 9:19
  • Thanks for the reply. I'm not allowed to use ODBC... It's a shame though... I know it's much easier if I do that. Commented Mar 28, 2014 at 9:20
  • also I remember that I couldn't use prefix dbo_ before table names - I was pulling my hair out until found out about that - after I removed that everything worked fine Commented Mar 28, 2014 at 9:25
  • Anyways, I really need help in making this work. I really do appreciate those people helping me out here. I'm still kinda stuck... Commented Mar 28, 2014 at 10:00
  • I've tried to revised my code and tried to display something: try { $dbh = new PDO ("sqlsrv:Server=$db_server;Database=$db_database;", $db_user, $db_passwd); foreach($dbh->query('SELECT * from dbo.BGCountry') as $row) { print_r($row); } $dbh = null; } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die(); } I'm still getting the same error: SQLSTATE[08001]: [Microsoft][SQL Server Native Client 11.0]TCP Provider: Timeout error [258] Commented Mar 28, 2014 at 11:02

3 Answers 3

1

The port should be func.website.com:8787. You have a typo with the comma.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply, I tried that already and that gives me the error [Microsoft][SQL Server Native Client 11.0]SQL Server Network Interfaces: Connection string is not valid [87] – that's why I used comma(,) instead of colon (:)
1

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
    )

)

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.