Jump to content

PHP and SQL connect


saint959

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

 

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
Share on other sites

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
Share on other sites

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.