A lightweight forum engine written in PHP. Repository is now obsolete and read-only. http://www.pioder.pl/uforum.html
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.

108 lines
2.6 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file includes/db.php
  5. * @version $Id$
  6. * @copyright 2009(c) PioDer <pioder@wp.pl>
  7. * @link http://pioder.gim2przemysl.int.pl/
  8. * @license GNU GPL v3
  9. **/
  10. if ( !defined('IN_uF') )
  11. {
  12. die('Hacking attempt');
  13. }
  14. $db;
  15. class DataBase
  16. {
  17. function db_connect()
  18. {
  19. global $db;
  20. $db = new mysqli(DB_HOST, DB_USER, DB_PASS);
  21. if (mysqli_connect_errno() != 0)
  22. {
  23. message_die(CRITICAL,' Could not connect to database server.',$db->error);
  24. }
  25. if (!$db->set_charset("UTF8"))
  26. {
  27. message_die(CRITICAL, 'Could not set character set UTF-8', $db->error);
  28. }
  29. if (!$db->select_db(DB_NAME))
  30. {
  31. message_die(CRITICAL,' Could not select database.', $db->error);
  32. }
  33. }
  34. function sql_query($sql, $type, $msg, $no_count = false)
  35. {
  36. global $db;
  37. if (isset($_COOKIE['queries']))
  38. {
  39. $no_count = false;
  40. if(!$no_count)
  41. {
  42. $_COOKIE['queries'] = $_COOKIE['queries']+1;
  43. }
  44. }
  45. //echo '<span class="fsmall">'.$sql.'<br></span>'; //for optimizing only
  46. if (!$query = $db->query($sql))
  47. {
  48. message_die($type, $msg, $db->error);
  49. }
  50. return $query;
  51. }
  52. function fetch($query)
  53. {
  54. return $query->fetch_assoc();
  55. }
  56. function num_rows($query)
  57. {
  58. if ($query===true || $query===false)
  59. {
  60. return 0;
  61. }
  62. else
  63. {
  64. return mysqli_num_rows($query);
  65. }
  66. }
  67. function new_id($table)
  68. {
  69. global $db;
  70. //check table id
  71. switch($table)
  72. {
  73. case BANLIST_TABLE: { $id = 'b_id'; break; }
  74. case CATS_TABLE: { $id = 'c_id'; break; }
  75. case CENSORLIST_TABLE: { $id = 'w_id'; break; }
  76. case FORUMS_TABLE: { $id = 'f_id'; break; }
  77. case GROUPS_TABLE: { $id = 'g_id'; break; }
  78. case PM_INBOX_TABLE: { $id = 'm_id'; break; }
  79. case PM_SENTBOX_TABLE: { $id = 'm_id'; break; }
  80. case POSTS_TABLE: { $id = 'p_id'; break; }
  81. case TOPICS_TABLE: { $id = 't_id'; break; }
  82. case SESSIONS_TABLE: { $id = 's_id'; break; }
  83. case SKINS_TABLE: { $id = 's_id'; break; }
  84. case SMILES_TABLE: { $id = 's_id'; break; }
  85. case USERS_TABLE: { $id = 'u_id'; break; }
  86. case USERS_GROUP_TABLE: { $id = 'id'; break; }
  87. case WARNINGS_TABLE: { $id = 'w_id'; break; }
  88. }
  89. $sql = "SELECT `$id` FROM $table ORDER BY `$id` DESC LIMIT 1";
  90. $return_id = DataBase::fetch(DataBase::sql_query($sql,GENERAL,'Error with obtain last id.<br> File: db.php, Line: '.__LINE__));
  91. $return_id = $return_id[$id];
  92. $return_id = $return_id+1;
  93. return $return_id;
  94. unset($table, $return_id, $id, $sql);
  95. }
  96. }
  97. ?>