Can't get PHP to talk to SQL Server via SQLSRV...

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Can't get PHP to talk to SQL Server via SQLSRV...

Postby DKY » 02. April 2013 04:19

Trying desperately to get xampp to talk with mssql server to no avail. I've looked over a few posts here on this forum but am having no luck. I went to this link
http://www.php.net/manual/en/sqlsrv.installation.php
and downloaded the drivers to my ext directory I then added these two lines in my php.ini file
extension=php_pdo_sqlsrv_53_ts_vc9.dll
extension=php_sqlsrv_53_ts_vc9.dll

Finally after restarting I tried this simple connection
Code: Select all
<?php


/* CONNECT TO THE DATABASE */
$connectionInfo = array('UID'=>'', 'PWD'=>'', 'Database'=>'dia2');

/*USE DB CONNECTION ABOVE TO CONNECT TO THE SERVER */
$conn = sqlsrv_connect('brksvp306\BRKSQL01', $connectionInfo);

/* STORE SQL IN A VARIABLE */
   $sql = "SELECT stcname, shipto FROM DIA2.dbo.dealers ORDER BY stcname";

/* RUNNING THE SQL */
$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false ) {
    if( ($errors = sqlsrv_errors() ) != null) {
        foreach( $errors as $error ) {
            echo "<BR>SQLSTATE: ".$error[ 'SQLSTATE']."<br />";
            echo "code: ".$error[ 'code']."<br />";
            echo "message: ".$error[ 'message']."<br />";
        }
    }
}


?>

only to get this error
Warning: sqlsrv_query() expects parameter 1 to be resource, boolean given in F:\xampp\WebPages\PR\PartReviewResultsms.php on line 14

SQLSTATE: IMSSP
code: -14
message: An invalid parameter was passed to sqlsrv_query.


Running
XAMPP 1.7.7
Windows Server 2003 sp2
PHP Version 5.3.8
DKY
 
Posts: 15
Joined: 23. March 2006 21:35
Operating System: Windows Server 2003 sp2

Re: Can't get PHP to talk to SQL Server via SQLSRV...

Postby Altrea » 02. April 2013 08:40

Use sqlsrv_errors().
Your connection could not be established.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Can't get PHP to talk to SQL Server via SQLSRV...

Postby DKY » 02. April 2013 12:46

Is there something more to sqlsrv_errors()? I'm using it above and it gives me this error
Warning: sqlsrv_query() expects parameter 1 to be resource, boolean given in F:\xampp\WebPages\PR\PartReviewResultsms.php on line 14

SQLSTATE: IMSSP
code: -14
message: An invalid parameter was passed to sqlsrv_query.


Trying to figure out why a connection can't be established since the same log in information works on the server that has the sql server on it using IIS so it's not the name, password or database information... I need to get the connection on this other server though as the IIS is locked down...
Do you think I could have the wrong extensions? or maybe I'm referring to the wrong extensions in php.ini???
Thanks in advance!
DKY
 
Posts: 15
Joined: 23. March 2006 21:35
Operating System: Windows Server 2003 sp2

Re: Can't get PHP to talk to SQL Server via SQLSRV...

Postby Altrea » 02. April 2013 12:48

DKY wrote:Is there something more to sqlsrv_errors()? I'm using it above and it gives me this error

Because you don't place it everywhere it is possible.
You can use it also to check the result if sqlsrv_connect()

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Can't get PHP to talk to SQL Server via SQLSRV...

Postby DKY » 02. April 2013 12:54

How do I do that? I tried
Code: Select all
echo sqlsrv_connect('brksvp306\BRKSQL01', $connectionInfo);

but nothing echoed out...
DKY
 
Posts: 15
Joined: 23. March 2006 21:35
Operating System: Windows Server 2003 sp2

Re: Can't get PHP to talk to SQL Server via SQLSRV...

Postby Altrea » 02. April 2013 12:56

Thats why i linked to the sqlsrv_errors() documentation.
It contains a full example (i quote just the relevant part)
Code: Select all
<?php
$serverName = "serverName/sqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
     die( print_r( sqlsrv_errors(), true));
}
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Can't get PHP to talk to SQL Server via SQLSRV...

Postby DKY » 02. April 2013 13:04

okay, so that's really weird.
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'
Yet it works on the local machine... Wonder if there's some sort of setting on the SQL server to allow externals as anonymous?
DKY
 
Posts: 15
Joined: 23. March 2006 21:35
Operating System: Windows Server 2003 sp2

Re: Can't get PHP to talk to SQL Server via SQLSRV...

Postby Altrea » 02. April 2013 13:16

If you don't specify Username and Password Microsoft SQL Server tries to connect with the logged in user via Kerberos. This truely works on the local database server but can fail from remote connections.
But that is not a XAMPP problem and i don't have much experiences with MSSQL Servers to be any help for you.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 109 guests