Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <?php
  2. //1. Create a database connection
  3. //$connection = mysql_connect("server", "user", "password");
  4. //$connection = mssql_connect("server", "user", "password");
  5. //handle is a reference to the connection
  6. $mysqli = mysqli_connect("localhost", "root", "psu", "ist402");
  7. if ($mysqli->connect_errno) {
  8. printf("Connect failed: %s\n", $mysqli->connect_error);
  9. exit();
  10. }
  11. ?>
  12. <html>
  13. <head>
  14. <title>Database</title>
  15. </head>
  16. <body>
  17. Five Steps for PHP Database Interaction<br />
  18. 1. Create the connection<br />
  19. 2. Select a database<br />
  20. 3. Preform database query<br />
  21. <?php
  22. //3 Perform database query
  23. $result = $mysqli->query("SELECT * from tblStudent");
  24. printf("Select returned %d rows.\n", $result->num_rows);
  25. $result->close();
  26. ?>
  27. 4. Use returned data (if any)<br />
  28. 5. Close the connection<br />
  29.  
  30. </form>
  31. </body>
  32. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement