thagafnh Posted June 17, 2008 Share Posted June 17, 2008 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 More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 Are you saying that your database server is running on your local machine while your webserver is remote? Or is this all on one machine? Link to comment https://forums.phpfreaks.com/topic/110653-connetinivity/#findComment-567665 Share on other sites More sharing options...
thagafnh Posted June 17, 2008 Author Share Posted June 17, 2008 Hi , The data base name is TPCH created in SQL server and running at my machine , while the PHP i ran it in the server that is located in my colloge . Thanks Link to comment https://forums.phpfreaks.com/topic/110653-connetinivity/#findComment-567670 Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 Then its really not that simple. Do you have a static ip address? Otherwise you'll need to setup something like dynamic DNS before you can even attempt to connect to your machine remotely. Link to comment https://forums.phpfreaks.com/topic/110653-connetinivity/#findComment-567673 Share on other sites More sharing options...
thagafnh Posted June 17, 2008 Author Share Posted June 17, 2008 Can I run the PHP in the same machine because the data base in the same machine . If yes How . I need to make it very simple . I need to see how PHP access the data base that I have been created it. Thanks for your help Link to comment https://forums.phpfreaks.com/topic/110653-connetinivity/#findComment-567676 Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 Can I run the PHP in the same machine because the data base in the same machine . Yes, you can setup a testing server on your local machine. You will need to install a mod_php enabled webserver. Link to comment https://forums.phpfreaks.com/topic/110653-connetinivity/#findComment-567683 Share on other sites More sharing options...
thagafnh Posted June 17, 2008 Author Share Posted June 17, 2008 Can you send me the site for installation , I have Windows Vista at my machine . Thanks for your help Link to comment https://forums.phpfreaks.com/topic/110653-connetinivity/#findComment-567686 Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 Use Apache as your web server and php is available here. You mighht also find it easier to simply install a package like xampp (google it). Link to comment https://forums.phpfreaks.com/topic/110653-connetinivity/#findComment-567687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.