Closed Thread Icon

Topic awaiting preservation: Connect to mssgl 2005 database using php & Dreamweaver (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26725" title="Pages that link to Topic awaiting preservation: Connect to mssgl 2005 database using php &amp;amp; Dreamweaver (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Connect to mssgl 2005 database using php &amp; Dreamweaver <span class="small">(Page 1 of 1)</span>\

 
Hustluz
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2003

posted posted 09-26-2005 14:35

Can anyone else help me im trying to connect to a mssql database created in mssgl 2005 using php. the code that i am using to connect is:

// Connecting to and selecting a database
$connect = mssql_connect('localhost', $user, $passwd)
or die('Could not connect: ' . mysql_error());
echo '<b>Step 1:</b> Connected successfully! <BR>';

$db = 'localhost';
mysql_select_db($db) or die('Could not select database ('.$db.') because of : '.mysql_error());
echo '<b>Step 2:</b> Connected to ('.$db.') successful!<BR>';

// Now we close the connection...
mysql_close($connect);

The error message that i am getting is:

Fatal error: Call to undefined function mssql_connect() in c:\program_files\wamp\www\learning_php\working_with_databases\connecting_to_data.php on line 8


is there something that im missing. or can someone correct me.

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 09-26-2005 14:59

is what you are showing the connecting_to_data.php file?

this part: $db = 'localhost'; can't be right. THis needs to be the name of the database. localhost is the server.

in the first string, you have localhost and then variables for the user and pass. Might go ahead and set the server as a variable also, just for consistancy. (correct me if Im wrong on that)

You need to go ahead and set the database that you are going to use before you try to connect to it.

So,

//first to define some variables
$myServer = "localhost";
$myUser = "username";
$myPass = "password";
$db = "database";

//Connecting to and selecting database
$connect = @mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
echo '<b>Step 1:</b> Connected successfully! <BR>';

//Right here I think is your problem. You have the database set to the server.
//No need to define the variable again since it's at the top there.
$d = @mssql_select_db($db, $connect)
or die("Couldn't open database $db");
echo '<b>Step 2:</b> Connected to ('.$db.') successful!<BR>';

//now we can close the connection to the database
mysql_close($connect);



So make sure that you first connect to the server with the username and password, then connect to the database (I think this is where you are having the problem) and then you can do all your queries and stuff and after the queries, you can close the connection.

Later,

C:\

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 09-26-2005 15:20

your error message says that the mssql module for php is not loaded.

Find your php.ini file and uncomment the mssql.dll extension.
Then restart apache.
If it doesn't come up again, you don't have that file and will need to find it somewhere on the net, matching to the php you've installed.

Hustluz
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2003

posted posted 09-27-2005 01:39

Okay thanx i fixed the problem with the php.ini file and now i dont get a server error. but im still not connecting. i wondering if i didnt set up microsoft sql server the right way. how do i know what folder the server should be on. or do i not need the server and just the database file to connect

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 09-27-2005 01:47

First what method are you using to connect.

In your file you're mixing mysql with mssql commands. In Cprompt's example he's got the @ signs which suppress error reporting so remove those to get a better error message.

You need the server to connect. You may want to see if there's a MSSQL client tool out there that you can try to connect with to make sure your settings are right.

Finally check out the PHP.net page there are a bunch of fixes for connection problems in the comments.



.:[ Never resist a perfect moment ]:.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 09-27-2005 08:25

try connecting with the query analyzer to see if your mssql server is up at all.

« BackwardsOnwards »

Show Forum Drop Down Menu