Jump to content

Connetinivity


thagafnh

Recommended Posts

Hi all ,

 

I have sql server installed at my machine .

User name : sa

Server name : NABEEL-PC

Password : nabeel

 

I have written this code to be connected to my Data base that has been created by me in SQL . The problem that I do not how to connect . I have the PHP file running in the server , but the data base is under my machine How they can talk to each other . Please help me thanks

 

<?php

$myServer = "NABEEL-PC";

$myUser = "sa";

$myPass = "nabeel";

$myDB = "tpch";

 

//connection to the database

$dbhandle = mssql_connect($myServer, $myUser, $myPass)

  or die("Couldn't connect to SQL Server on $myServer");

 

//select a database to work with

$selected = mssql_select_db($myDB, $dbhandle)

  or die("Couldn't open database $myDB");

 

//declare the SQL statement that will query the database

$query = "SELECT id, name, year ";

$query .= "FROM cars ";

$query .= "WHERE name='BMW'";

 

//execute the SQL query and return records

$result = mssql_query($query);

 

$numRows = mssql_num_rows($result);

echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";

 

//display the results

while($row = mssql_fetch_array($result))

{

  echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";

}

//close the connection

mssql_close($dbhandle);

?>

Link to comment
https://forums.phpfreaks.com/topic/110653-connetinivity/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.