db.php 692 B

123456789101112131415161718192021222324252627
  1. <?php
  2. /**
  3. * Creates a database connection using the data in the config files.
  4. *
  5. * @return MySQL_connection Connection to the database.
  6. */
  7. function start_db(){
  8. global $auth;
  9. $db = mysqli_connect($auth["host"], $auth["user"], $auth["pass"], $auth["name"]);
  10. // Check connection
  11. if (mysqli_connect_errno()){
  12. error_log("Failed to connect to database: " . mysqli_connect_error());
  13. return -1;
  14. }
  15. //Set encoding options
  16. mysqli_set_charset($db, "utf-8");
  17. header("Content-Type: text/html; charset=utf8");
  18. mysqli_query($db, "SET NAMES utf8;");
  19. return $db;
  20. }
  21. ?>