php and mssql

  • _nYght
  • Novice
  • Novice
  • _nYght
  • Posts: 17

Post 3+ Months Ago

why can't connect to a sql server with php using the mssql extension, i'm using the windows authentication mode and mssql_connect() but i'm only get the message
Code: [ Select ]
[b]Warning[/b]: mssql_connect(): Unable to connect to server: XPCLON in C:\Inetpub\wwwroot\intranet\index.php on line 4


the line 4 is
PHP Code: [ Select ]
$linkid=mssql_connect('XPCLON','','');
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Well by the looks of it, it might be am authentication issue (although I'm sure php would have told you that)

is the sever local? if the server is sitting on the localhost (same server as php) try localhost as the name rather than XPCLON.

If all else fails you might just want to install the SQL ODBC drivers and have PHP use that.
  • Rogue Forces
  • Beginner
  • Beginner
  • User avatar
  • Posts: 51
  • Loc: Kentucky

Post 3+ Months Ago

Try switching over to SQL mixed mode authentication and use the "sa" login. (without the quote of course)

If it works you'll want to set up an application login and roles on the SQL Server and use that login from your application.

Hope this helps.
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

I agree, it looks like an authentication issue, from the code snippet...

There might be a better way (actually, I know there is, but I can't find any more recent code examples I've used), but here the code I've used in the past:
PHP Code: [ Select ]
 
$connection = mysql_connect("HOSTNAME","USERNAME","PASSWORD") or die("<p>Could not connect to database: " . mysql_error());
 
if(isset($connection)){ $db =  mysql_select_db("DBNAME") or die("<p>Could not select database" . mysql_error()); }
 
$sql = "SQL QUERY";
 
$rs = mysql_query($sql) or die("<p>Query failed" . mysql_error());
 
 
 
 
  1.  
  2. $connection = mysql_connect("HOSTNAME","USERNAME","PASSWORD") or die("<p>Could not connect to database: " . mysql_error());
  3.  
  4. if(isset($connection)){ $db =  mysql_select_db("DBNAME") or die("<p>Could not select database" . mysql_error()); }
  5.  
  6. $sql = "SQL QUERY";
  7.  
  8. $rs = mysql_query($sql) or die("<p>Query failed" . mysql_error());
  9.  
  10.  
  11.  
  12.  


Note: Words in caps should be replaced with your specific information. You should never allow unauthenticated access to you database... never never never. Also, you should never use the root user either. I usually create a user that has only the rights needed to execute the queries needed by the application, and no others (if the app never runs a DELETE query, which mine rarely do, then it can't delete... if there is no need to do anything but SELECT... there you go...)

.c

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 136 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.