saint959 Posted June 25, 2007 Share Posted June 25, 2007 Hi All, I am hoping someone can help me out. i am attempting to connect to a Microsoft SQL database. below is the code i am using as a test just to see if the connection is being made <?PHP msql_connect('servername','username','password') or die ('Unable to connect to server.'); msql_select_db('tablename') or die ('Unable to select database.'); ?> If anyone has any ideas please, any help will be hugely appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
suma237 Posted June 25, 2007 Share Posted June 25, 2007 code for connecting mysql with php $link = mysql_connect("localhost","databasename","password") or die("Could not connect: " . mysql_error()); mysql_select_db("databsename"); Quote Link to comment Share on other sites More sharing options...
suma237 Posted June 25, 2007 Share Posted June 25, 2007 sorry one change..in the above code $link = mysql_connect("localhost","username","password") or die("Could not connect: " . mysql_error()); mysql_select_db("databasename"); Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 25, 2007 Share Posted June 25, 2007 try this ok. <?PHP $db=mssql_connect("servername","username","password"); mssql_select_db("table",$db) or die ("Unable to select database."); ?> i am pretty sure it mssql ok Quote Link to comment Share on other sites More sharing options...
saint959 Posted June 25, 2007 Author Share Posted June 25, 2007 Hi redarrow, thanks for the reply. I am receiving the below error: Warning: Wrong parameter count for msql_connect() in "file directory" on line 7 Warning: msql_select_db(): supplied argument is not a valid mSQL-Link resource in "file directory" on line 8 Unable to select database. IS there a difference between msql and mssql??? Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 25, 2007 Share Posted June 25, 2007 are you using msql sever for windows Quote Link to comment Share on other sites More sharing options...
suma237 Posted June 25, 2007 Share Posted June 25, 2007 check the status of the connection <? $host = "hostname"; $user = "username"; $passwd = "passwd"; $connect_status = mysql_connect($host,$user,$passwd); echo "mySQL connect status: $connect_status\n"; ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 25, 2007 Share Posted June 25, 2007 corect connection format <?php while(!$connection){ @$connection = mssql_connect($cfg['server'],$cfg['username'],$cfg['password']); } $db = mssql_select_db($cfg['database'],$connection) or die("Error selecting the database"); ?> Quote Link to comment Share on other sites More sharing options...
saint959 Posted June 25, 2007 Author Share Posted June 25, 2007 hi redarrow, yes we are using SQL 2005 for windows. i have requested that the mssql extension be included in the php.ini and will test that in a few mins. Thanks for the help so far, it is much appreciated, will try that now suma237, thanks for your help but i am not trying to connect to a MySQL database. I am struggling to connect to a Microsoft Database which uses a different connection to MySQL. Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 25, 2007 Share Posted June 25, 2007 got this aswell m8 i am trying sorry for not nowing m8. <html> <body> <?php $con = mssql_connect ("<ip of the server SQL>", "sa", ""); mssql_select_db ("<Data Base>", $con); $sql= "SELECT * FROM <Table>"; $rs= mssql_query ($sql, $con); echo "The field number one is: "; echo mssql_result ($rs, 0, 0); mssql_close ($con); ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.