Guest User

Untitled

a guest
Jun 17th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. Sample 1
  2.  
  3. <?php
  4. $myServer = "localhost";
  5. $myUser = "your_name";
  6. $myPass = "your_password";
  7. $myDB = "examples";
  8.  
  9. //connection to the database
  10. $dbhandle = mssql_connect($myServer, $myUser, $myPass)
  11.   or die("Couldn't connect to SQL Server on $myServer");
  12.  
  13. //select a database to work with
  14. $selected = mssql_select_db($myDB, $dbhandle)
  15.   or die("Couldn't open database $myDB");
  16.  
  17. //declare the SQL statement that will query the database
  18. $query = "SELECT id, name, year ";
  19. $query .= "FROM cars ";
  20. $query .= "WHERE name='BMW'";
  21.  
  22. //execute the SQL query and return records
  23. $result = mssql_query($query);
  24.  
  25. $numRows = mssql_num_rows($result);
  26. echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
  27.  
  28. //display the results
  29. while($row = mssql_fetch_array($result))
  30. {
  31.   echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
  32. }
  33. //close the connection
  34. mssql_close($dbhandle);
  35. ?>
  36.  
  37. _----------
  38.  
  39. Sample 2
  40.  
  41. <?php
  42. $Server = "localhost";
  43. $User = "your_name";
  44. $Pass = "your_password";
  45. $DB = "examples";
  46.  
  47. //connection to the database
  48. $dbconn = mssql_connect($Server, $User, $Pass)
  49.   or die("Couldn't connect to SQL Server on $Server");
  50.  
  51. //select a database to work with
  52. $selected = mssql_select_db($DB, $dbconn)
  53.   or die("Couldn't open database $myDB");
  54.  
  55. //declare the SQL statement that will query the database
  56. $query = "SELECT name from test ";
  57.  
  58. //execute the SQL query and return records
  59. $result = mssql_query($query);
  60.  
  61. $numRows = mssql_num_rows($result);
  62. echo "<h1>" &#46; $numRows &#46; " Row" &#46; ($numRows == 1 ? "" &#58; "s") &#46; " Returned </h1>";
  63.  
  64. //display the results
  65. while($row = mssql_fetch_array($result))
  66. {
  67.   echo "<br>" &#46; $row["name"&#93;;
  68. }
  69. //close the connection
  70. mssql_close($dbconn);
  71. ?>
Add Comment
Please, Sign In to add comment