Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <?php
  9.  
  10. $data_source='SQLSERVER2008EXAMPLES';
  11. $user='sa';
  12. $password='testing123';
  13.  
  14. // connect to the SQL server using username and password
  15. $conn=odbc_connect($data_source,$user,$password);
  16. if (!$conn){ //checking if connection is established
  17. if (phpversion() < '4.0'){
  18. exit("Connection Failed:" . $php_errormsg );
  19. }
  20. else{
  21. exit("Connection Failed:" . odbc_errormsg() );
  22. }
  23. }
  24.  
  25. // here we can put our query
  26. $query="select sr.name, sr.phone from Sales_Rep sr, Car c where sr.name = c.seller and c.color = 'green';";
  27.  
  28. //execute the query
  29. $result=odbc_exec($conn,$query);
  30.  
  31. // check for an error
  32. if (!$result){echo "Problem with query";}
  33.  
  34. //fetch the result and show it in the loop to the table
  35. echo "<table>";
  36. while (odbc_fetch_row($result)){
  37. $col1=odbc_result($result, "name");
  38. $col2=odbc_result($result, "phone");
  39. echo "<tr>";
  40. echo "<td>$col1</td>";
  41. echo "<td>$col2</td>";
  42. echo "</tr>";
  43. }
  44. echo "</table>";
  45.  
  46. // Disconnect from the database
  47. odbc_close($conn);
  48. ?>
  49. </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement