Connecting to MS SQLSERVER 2005

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

Connecting to MS SQLSERVER 2005

Postby AndrewKKWalker » 30. March 2009 15:55

:?:
I know this is not really the place to post this.
However, can anyone point me in the right direction for information,
regarding how to connect to MS SQL SERVER 2005 via PHP.
I am running Apache 2.2. and PHP 5 currently XAMPP 1.7.0

I have Googled and looked at lot's of sites, BUT nowhere I have found really
gives a valid example of how to do this that works.

I would be running on Windows XP/2000
The Server is localhost.
Eventually it might be elsewhere, but at the moment I just want to be able to get a connection.
It would be using SQL Authentification.

Any pointers would be good.

In an ideal world, I would use MYSQL, in which case I would not need to ask any questions.

Thanks

Andrew
Andrew
AndrewKKWalker
 
Posts: 33
Joined: 27. March 2009 01:46
Location: Cambridge England

Re: Connecting to MS SQLSERVER 2005

Postby Wiedmann » 30. March 2009 17:05

can anyone point me in the right direction for information, regarding how to connect to MS SQL SERVER 2005 via PHP

http://de.php.net/manual/en/book.mssql.php
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Connecting to MS SQLSERVER 2005

Postby AndrewKKWalker » 30. March 2009 17:54

Thanks....
Looks like I've got a lot of reading and work to do.

Any more info or examples greatly appreciated.

AW
Andrew
AndrewKKWalker
 
Posts: 33
Joined: 27. March 2009 01:46
Location: Cambridge England

Re: Connecting to MS SQLSERVER 2005

Postby AndrewKKWalker » 30. March 2009 22:39

PHP.INI ?

The location of this seems to be varied depending upon what you read.

I am assuming it is the one in C:\xampp\php

But others say it is in C:\xampp\apache\bin

or c:\windows

I am trying to add the line

extension=php_sqlsrv.dll to enable connection to mssql server

I have done this in the file php.ini in C:\xampp\php

The File php_sqlsrv.dll was placed into folder c:\xampp\php\ext
this is the extensions folder referenced in phpinfo()


I stopped and started the Apache Server, but when I try to connect with php using

$serverName = "(local)";
$connectionInfo = array( "Database"=>"Training");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
[/b]

I get the error message

Fatal error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\ConnectTraining.php on line

If I try to specify SQL Server Name and SQL Login Details with

$serverName = "svr-sql";
$connectionOptions = array("Database"=>"Training","UID"=>"MYUID","PWD"=>"MYPWD");
$conn = sqlsrv_connect( $serverName, $connectionOptions);


I get the same error message

This implies that the sqlsrv_connect function call is either not defined correctly
or
It is not being referenced via the php.ini extensions function.

Not sure how to check which it is or what I am doing wrong.

Any ideas or help much appreciated.

Andrew
Last edited by AndrewKKWalker on 30. March 2009 22:48, edited 2 times in total.
Andrew
AndrewKKWalker
 
Posts: 33
Joined: 27. March 2009 01:46
Location: Cambridge England

Re: Connecting to MS SQLSERVER 2005

Postby Wiedmann » 30. March 2009 22:46

The location of this seems to be varied depending upon what you read.

Look in the phpinfo() output (or read the XAMPP for Windows homepage).
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Connecting to MS SQLSERVER 2005

Postby AndrewKKWalker » 30. March 2009 23:19

I have had a look in phpinfo()

It Reports the following 2 entries

Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\xampp\apache\bin\php.ini


This seems to be a conflict and nothing to do with C:\xampp\php

I have tried putting the same ini file in each of these folders, but it makes NO difference to end result.

I assume it should only be in 1, but I have no idea which or how to set it up now.

I have also looked in the Apache Error Log and it reports the following

PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\xampp\\php\\ext\\php_sqlsrv.dll' - The specified module could not be found.\r\n in Unknown on line 0


However, the entry in php.ini shows as

extension_dir C:\xampp\php\ext\


So not sure what is going on here, nor where this is actually set.

Also the \\ are a concern since I did not set this path

Anyone got any suggestions as to how to get the module to load, or do I need to do a machine reboot. :?


AH HA!

Just found a thread that says it is a problem with the Installer and If I download XAMPP as a zip file and just unpack it is ok.
Lot of work now I have everything working.
Probably have to give it a go unless someone can tell me how to fix this another way (Please).


Andrew
Andrew
AndrewKKWalker
 
Posts: 33
Joined: 27. March 2009 01:46
Location: Cambridge England

Re: Connecting to MS SQLSERVER 2005

Postby Wiedmann » 30. March 2009 23:45

Code: Select all
[b]Loaded [/b]Configuration File C:\xampp\apache\bin\php.ini

That's the one, PHP is currently using.

PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\xampp\\php\\ext\\php_sqlsrv.dll'

Did you have this extension?
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Connecting to MS SQLSERVER 2005

Postby AndrewKKWalker » 31. March 2009 00:47

Did you have this extension?


Yes see line from earlier in thread

The File php_sqlsrv.dll was placed into folder c:\xampp\php\ext
this is the extensions folder referenced in phpinfo()


I also did a complete clear down and rebuild from zip files only.
Made NO difference at all and still get same problem and same entry in the Apache error log.

Either I am missing something, or I am being an idiot somewhere.

Andrew
Andrew
AndrewKKWalker
 
Posts: 33
Joined: 27. March 2009 01:46
Location: Cambridge England

Re: Connecting to MS SQLSERVER 2005

Postby Wiedmann » 31. March 2009 08:09

extension=php_sqlsrv.dll to enable connection to mssql server
The File php_sqlsrv.dll was placed into folder c:\xampp\php\ext

You are not using the PHP from XAMPP? (because XAMPP is using a thread safe PHP)
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Connecting to MS SQLSERVER 2005

Postby AndrewKKWalker » 31. March 2009 09:39

Yes I am, at least I assume I am.
It was downloaded from XAMPP site.

There was NO reference to either the standard or thread safe version of the ms-sql driver dll's in it.
I checked in the ext folder before I downloaded them
I had to go and get these elsewhere.
Now I have them, and BOTH are now in the ext folder.

I have tried both installed and zipped versions and neither have the sqlsrv dll's



I got the ms-sql drivers from the Microsoft site.

So anyway, back to the question, how can I instruct XAMPP to use these files?

Andrew
Andrew
AndrewKKWalker
 
Posts: 33
Joined: 27. March 2009 01:46
Location: Cambridge England

Re: Connecting to MS SQLSERVER 2005

Postby Wiedmann » 31. March 2009 10:24

There was NO reference to either the standard or thread safe version of the ms-sql driver dll's in it.

Sure. Just read the documentation, which is part of the Microsoft SQL Server Driver for PHP package, more carefully...
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Connecting to MS SQLSERVER 2005

Postby AndrewKKWalker » 31. March 2009 11:14

Sure. Just read the documentation, which is part of the Microsoft SQL Server Driver for PHP package, more carefully...


:?: Not sure what your point is there.

My earlier comment was nothing to do with the Microsoft documentation.
It was that the sqldrv.dll and sqldrv-ts.dll drivers files
did not come with xampp, (at least not mine) I had to go and get them.
I then read the MS documentation that told me which files, and where to put them.
I then edited the php.ini file and anything else needed to get them installed properly and did what it said,
(as explained earlier), or at least what I thought it told me to do, but I still cannot get it to work.

So, IF I have missed something, please let me know what or where so I can rectify my error.

But my reading documentation again (which I just did) is not going to get me any closer, because....

Either I have misinterpreted and done it wrong,
or I have done it right, but it doesn't work.
Whatever the case it isn't working


Thanks

Andrew
Andrew
AndrewKKWalker
 
Posts: 33
Joined: 27. March 2009 01:46
Location: Cambridge England

Re: Connecting to MS SQLSERVER 2005

Postby Wiedmann » 31. March 2009 11:34

It was that the sqldrv.dll and sqldrv-ts.dll drivers files
did not come with xampp, (at least not mine) I had to go and get them.

Correct, because I've referred to the PHP mssql-extension, which is part of the XAMPP package, and not to the Microsoft SQL Server Driver for PHP.

I then read the MS documentation that told me which files, and where to put them.

Well, you have decided to use the Microsoft SQL Server Driver for PHP...

I then edited the php.ini file and anything else needed to get them installed properly and did what it said,
Code: Select all
extension=php_sqlsrv.dll

From the Microsoft SQL Server Driver for PHP documentation:
Microsoft wrote:Installation
When you unpack the downloaded files for this release, you will find the php_sqlsrv_ts.dll and php_sqlsrv.dll files. These files correspond to a thread-safe version and a non–thread-safe version (respectively) of the SQL Server 2005 Driver for PHP. Follow the installation instructions in the "Loading the Driver" topic in the documentation to install the driver.

Note: The php_sqlsrv_ts.dll file is compatible with php5ts.dll, and php_sqlsrv.dll is compatible with php5.dll.

Did you think "extension=php_sqlsrv.dll" is correct, if you have a thread safe PHP and a "php5ts.dll"?
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Connecting to MS SQLSERVER 2005

Postby AndrewKKWalker » 31. March 2009 18:28

Did you think "extension=php_sqlsrv.dll" is correct, if you have a thread safe PHP and a "php5ts.dll"?


Probably no, but I had no idea which one I needed, and anyway it didn't install either, and I was not aware of the others.

Unless you know where to look, it is very difficult to find all the information in one place.
Microsoft say one thing, then another site says something else, here it says something else, if you know where to look.

Also, many filenames (brief as they are), are impossible to figure out their purpose unless yo0u already know what it does.
php5ts.dll has really no hint in its name that it has the MSSQL support functions in it.
Also, are they the same names and parameters in use as those in sqlsrv-ts.dll

Based upon the number of people having issues with ini and config files on this message board alone, it is pretty obvious that
organised and structured documentation is hard to find even when it is avaialable.

I will now go away and experiment for a while because it is probably the best way to find out the actual solution.

It's my own fault for using MSSQL. It was easy with MYSQL
Andrew
AndrewKKWalker
 
Posts: 33
Joined: 27. March 2009 01:46
Location: Cambridge England

Re: Connecting to MS SQLSERVER 2005

Postby Wiedmann » 31. March 2009 18:48

Microsoft wrote:Note: The php_sqlsrv_ts.dll file is compatible with php5ts.dll,

You have a thread safe PHP and a php5ts.dll, you have to use this in your "php.ini":
Code: Select all
extension=php_sqlsrv_ts.dll



Microsoft say one thing, then another site says something else,

Not really, because they are talking about different things.

- Microsoft is talking about the "Microsoft SQL Server Driver for PHP" extension, and you have all infos about this extension on the Microsoft website, or in the docu which is part of this package.

- PHP is talking about the mssql extension (which is part of XAMPP), and you have all infos about this extension in the PHP manual. See my first answer to your question, that was a link to the PHP manual. Not Google or somehing else.
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Next

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 66 guests