"OdenseTrack" is a school assignment/project from AspIT https://aspit.dfine.net/odensetrack
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

dbclass.class.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * User: DFiNE
  4. * Date: 20/01/2019
  5. * Time: 13.05
  6. */
  7. class DBclass
  8. {
  9. var $classQuery;
  10. var $link;
  11. var $errno = '';
  12. var $error = '';
  13. // Connects to the database
  14. function __construct()
  15. {
  16. // Get the main settings from the array we just loaded
  17. $host = Config::$mysql_host;
  18. $name = Config::$mysql_db;
  19. $user = Config::$mysql_user;
  20. $pass = Config::$mysql_pass;
  21. // Connect to the database
  22. $this->link = new mysqli( $host , $user , $pass , $name );
  23. $this->link->set_charset("utf8"); // Set charset to UTF-8, always!
  24. }
  25. // Executes a database query
  26. function query( $query )
  27. {
  28. $this->classQuery = $query;
  29. return $this->link->query( $query );
  30. }
  31. function escapeString( $query )
  32. {
  33. return $this->link->escape_string( $query );
  34. }
  35. // Get the data return int result
  36. function numRows( $result )
  37. {
  38. return $result->num_rows;
  39. }
  40. function lastInsertedID()
  41. {
  42. return $this->link->insert_id;
  43. }
  44. // Get query using assoc method
  45. function fetchAssoc( $result )
  46. {
  47. return $result->fetch_assoc();
  48. }
  49. // Gets array of query results
  50. function fetchArray( $result , $resultType = MYSQLI_ASSOC )
  51. {
  52. return $result->fetch_array( $resultType );
  53. }
  54. // Fetches all result rows as an associative array, a numeric array, or both
  55. function fetchAll( $result , $resultType = MYSQLI_ASSOC )
  56. {
  57. return $result->fetch_all( $resultType );
  58. }
  59. // Get a result row as an enumerated array
  60. function fetchRow( $result )
  61. {
  62. return $result->fetch_row();
  63. }
  64. // Free all MySQL result memory
  65. function freeResult( $result )
  66. {
  67. $this->link->free_result( $result );
  68. }
  69. //Closes the database connection
  70. function close()
  71. {
  72. $this->link->close();
  73. }
  74. function sql_error()
  75. {
  76. if( empty( $error ) )
  77. {
  78. $errno = $this->link->errno;
  79. $error = $this->link->error;
  80. }
  81. return $errno . ' : ' . $error;
  82. }
  83. }