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 Link to comment https://forums.phpfreaks.com/topic/57055-php-and-sql-connect/ 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"); Link to comment https://forums.phpfreaks.com/topic/57055-php-and-sql-connect/#findComment-281891 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"); Link to comment https://forums.phpfreaks.com/topic/57055-php-and-sql-connect/#findComment-281892 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 Link to comment https://forums.phpfreaks.com/topic/57055-php-and-sql-connect/#findComment-281893 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??? Link to comment https://forums.phpfreaks.com/topic/57055-php-and-sql-connect/#findComment-281895 Share on other sites More sharing options...
redarrow Posted June 25, 2007 Share Posted June 25, 2007 are you using msql sever for windows Link to comment https://forums.phpfreaks.com/topic/57055-php-and-sql-connect/#findComment-281898 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"; ?> Link to comment https://forums.phpfreaks.com/topic/57055-php-and-sql-connect/#findComment-281899 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"); ?> Link to comment https://forums.phpfreaks.com/topic/57055-php-and-sql-connect/#findComment-281900 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. Link to comment https://forums.phpfreaks.com/topic/57055-php-and-sql-connect/#findComment-281901 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> Link to comment https://forums.phpfreaks.com/topic/57055-php-and-sql-connect/#findComment-281902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.