You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sql.php 925B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. require_once "utils.php";
  3. require_once "misc/config.php";
  4. function database_get()
  5. {
  6. static $init = 0;
  7. static $database = NULL;
  8. if ($init == 0)
  9. {
  10. $init = 1;
  11. global $database_host;
  12. global $database_port;
  13. global $database_name;
  14. global $database_user;
  15. global $database_pass;
  16. try
  17. {
  18. $database = new PDO("mysql:host=$database_host;port=$database_port;".
  19. "dbname=$database_name", $database_user,
  20. $database_pass);
  21. }
  22. catch (Exception $e)
  23. {
  24. error(500, "Database Fail Connect");
  25. }
  26. }
  27. return $database;
  28. }
  29. function database_exec($query, $args)
  30. {
  31. $q = database_get()->prepare($query);
  32. if (!$q->execute($args))
  33. error(500, "Database Fail Query");
  34. return $q;
  35. }
  36. function database_query($query)
  37. {
  38. $q = database_get()->query($query);
  39. if (!$q)
  40. error(500, "Database Fail Query");
  41. return $q;
  42. }
  43. ?>