Guest User

Untitled

a guest
May 9th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. [MSHOSTNAME]
  2. host = mshostname.example.com
  3. port = 1433
  4. tds version = 8.0
  5.  
  6. <?php
  7.  
  8. $myUser = "your_name";
  9. $myPass = "your_password";
  10. $myDB = "examples";
  11.  
  12. //connection to the database
  13. $dbhandle = mssql_connect(MSHOSTNAME, $myUser, $myPass)
  14. or die("Couldn't connect to SQL Server on $myServer");
  15.  
  16. //select a database to work with
  17. $selected = mssql_select_db($myDB, $dbhandle)
  18. or die("Couldn't open database $myDB");
  19.  
  20. //declare the SQL statement that will query the database
  21. $query = "SELECT id, name, year ";
  22. $query .= "FROM cars ";
  23. $query .= "WHERE name='BMW'";
  24.  
  25. //execute the SQL query and return records
  26. $result = mssql_query($query);
  27.  
  28. $numRows = mssql_num_rows($result);
  29. echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
  30.  
  31. //display the results
  32. while($row = mssql_fetch_array($result))
  33. {
  34. echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
  35. }
  36. //close the connection
  37. mssql_close($dbhandle);
  38. ?>
Add Comment
Please, Sign In to add comment