Advertisement
Guest User

Basic database configuration using the MySql Object

a guest
Oct 13th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. <?php
  2.  
  3. // PHP databse config file for easy reusability
  4.  
  5. $hostname = "localhost";        // Hostname to connect with
  6. $username = "username";         // Username for database
  7. $password = "password";         // Password for database
  8.  
  9. // Create new object for the database connection and store it in a variable
  10. $conn = new mysqli($hostname, $username, $password);
  11.  
  12. // If the connection is unsuccessful
  13. if (!$conn) {
  14.     // Terminate the script
  15.     die ("Connection failed: " . $conn->connect_error);
  16. }
  17.  
  18. // Use database school
  19. mysqli_query($conn, "USE school");
  20.  
  21. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement