mysql.php 917 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. class mysql {
  3. var $error = "";
  4. var $result = false;
  5. var $link = null;
  6. function mysql () {
  7. global $dsn;
  8. $this->link = mysqli_connect ($dsn['hostspec'], $dsn['username'], $dsn['password']) or die("could not connect to db");
  9. if (!$this->link) {
  10. echo "Error: Unable to connect to MySQL." . PHP_EOL;
  11. echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
  12. echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
  13. exit;
  14. }
  15. if ( ! mysqli_select_db ($this->link, $dsn['database'])) {
  16. $this->error = mysqli_error ($this->link);
  17. }
  18. }
  19. function query ($query) {
  20. if ($this->result = mysqli_query ($this->link, $query)) {
  21. return true;
  22. }
  23. else{
  24. $this->error = mysqli_error ($this->link);
  25. return false;
  26. }
  27. }
  28. function escape ($string) {
  29. return mysqli_real_escape_string ($this->link, $string);
  30. }
  31. }
  32. ?>