IIS, MS_SQL, PHP - Getting Connected

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ocpaul20
Forum Newbie
Posts: 12
Joined: Thu Jul 05, 2007 3:53 am

IIS, MS_SQL, PHP - Getting Connected

Post by ocpaul20 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


As you can see, this is my Mickey-Mouse test program to connect to MSSQL server 2005 Express

I can connect using the named pipe details found under 'properties' of the named pipe, 
but I cannot connect using any other connection string. 

What should go after the host= ? The statements I have seen put localhost there but I have tried that and, anyway,  it does not relate to my MSSQL server's name. 
I seem to have tried all kinds of strings and none seem to work - except for the named pipe connection.
I have tried 
MSSQL1
MSSQL$SQLEXPRESS
WEIFAN\SQLEXPRESS
WEIFAN\\SQLEXPRESS
localhost
I have run out of things to try....
 

I am fairly sure that I have got everything set up correctly and the correct extensions enabled in php.ini.
so... what else can I try please?

[url=http://www.perriams.co.uk/images/mssql1.gif]MS-SQL Server Management Studio Express screen[/url]

Code: Select all

try {
	echo "<BR>========= Connecting.... ======================";
	// OK connects fine
	// $dbh = new PDO('mssql:host=\\\\.\pipe\\MSSQL$SQLEXPRESS\\sql\\query;dbname=project13', ocpaul20, pword);

	// This will not connect
	$dbh = new PDO('mssql:host=localhost;dbname=project13', ocpaul20, pword);
	echo "<BR>========= Connected Now. ======================";

} catch (PDOException $e) {
	echo '<BR>Connection failed ';
   	print "<BR><BR>(1)Error!: " . $e->getMessage() . "<br/>";
   	die();
}
$dbh = null; // close connection
echo "<BR>============= CLOSED =====================";
exit;

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

I'm not a MS SQL expert, but I think it depends on how it was installed, as a Windows service, for example. If it runs as a service, 'localhost' should be the host, as far as I know.
Post Reply