Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connecting to a ms sql server

Status
Not open for further replies.

mkohl

Programmer
Feb 22, 2005
82
US
Does anyone know the script I can use to connect to a ms sql server.

I tried this basic code, and this did not work.

<?php
<?php
$dsn ="dsn";
$uid ="uid";
$pwd ="pwd";
$network="network";
$connect = odbc_connect($dsn,$uid,$pwd);
echo "This is a test.";
?>

I basically wrote this script just to see if a connection is established. I also tried "mssql_connect" that did not seem to work either.

my boss, gave me information for variable "$network" but I'm unsure how this will be involved in the data connection.

-Mike
 
I am like yourself just starting to talk to an ms sql server.

Just is what I done to get things working

I am using php 5.0.3 on a windows 2000 pc.

I went into the php.ini file and enabled the mssql.dll line.

I then restarted apache.

I then used the following code

Code:
<?php
$db = @mssql_connect("server","username","password") or die("Unable to connect to server");
mssql_select_db("dbname");
$result = mssql_query("SELECT * FROM tablename");
print("<table border=1>");
print("<tr><th>Name</th></tr>");
for ($i=0; $i < mssql_num_fields($result); $i++) {
    print("<tr>");
    printf("<td>%s</td>", mssql_field_name($result, $i));
    print("</tr>");
}
print("</table>");
?>

 
remove the @ from this line while testing to get any errors displyed

$db = @mssql_connect(

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top