db_utils.php 572 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. /* Connect to the MySQL database */
  3. function db_connect() {
  4. include('config.php');
  5. if(isset($db_host, $db_username, $db_password, $db_name)) {
  6. // Create connection to database
  7. $conn = new mysqli($db_host, $db_username, $db_password, $db_name);
  8. if ($conn->connect_error) {
  9. echo 4004; // Unsuccessful connection to database
  10. }
  11. }
  12. else { // Connection variables not set
  13. echo 4005; // Respond with bad-request code
  14. }
  15. return $conn;
  16. }
  17. /* Closes the connection to the database */
  18. function db_close($conn) {
  19. $conn->close();
  20. }
  21. ?>