SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Connections

  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Connections

    Hey I'm having some problems connecting to my database using php.

    To connect to the database I am using this code:
    Code:
    <?php
    	$Conn = mssql_connect("The server","my username on the server","my password on the server") or die("ERROR connection server");
    	
    	echo 'Connection to server etablished<br />';
    	
    	$Db=mssql_select_db("the name of my database on the server",$Conn);
    	if($Db){
    		echo '$Db is good<br /><br />';
    		$query = mssql_query("SELECT * FROM player");
    		echo 'Query is good :) There are '.mssql_num_rows($query).' records<br />';
    		
    	
    		mssql_close($Conn);
    	}
    	else{
    		echo 'ERROR connection DB<br />';
    	}
    ?>
    When I run this code I get:
    ERROR connection serverPHP Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: ***** in ***\wwwroot\Ratefootball\databaseworking.*** on line 5

    Now unless I have the servername/username/password incorrect does that code look like it should work? Also in coldfusion you set up a DSN is that required in PHP or is this code all that is needed?

    If you do need a dsn is there a way to create/access it on a pc which doesnt give you access to control panel?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya, looks correct.

    mssql_connect() doesn't use a dsn for connection.

    The PDO extension uses a dsn, which also supports mssql, if you want to use that for working with the db instead.

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool well that one thing ticked off its not that i need a dsn. So is there any other reason why this wouldn't work? I'm pretty sure I've got the server,username,password,database correct.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •