PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/public_html/old/phorum/db/mysql.php

https://gitlab.com/cherian/xmec
PHP | 317 lines | 230 code | 40 blank | 47 comment | 18 complexity | 03d4e9ec2c40827e66b56101cb978954 MD5 | raw file
  1. <?php
  2. if ( defined( "_DB_LAYER" ) ) return;
  3. define("_DB_LAYER", 1 );
  4. if(!defined("PHORUM_ADMIN") && !function_exists("mysql_connect")){
  5. echo "<b>Error: You have configured Phorum to use MySQL. MySQL support is not available to PHP on this server.</b>";
  6. exit();
  7. }
  8. class phorum_db {
  9. var $connect_id;
  10. var $type;
  11. var $database;
  12. function phorum_db($database_type="mysql") {
  13. $this->type=$database_type;
  14. }
  15. function open($database, $host, $user, $password) {
  16. if(empty($user)){
  17. $this->connect_id=@mysql_connect();
  18. }
  19. else{
  20. $this->connect_id=@mysql_connect($host, $user, $password);
  21. }
  22. if ($this->connect_id) {
  23. $this->database=$database;
  24. if(@mysql_select_db($this->database, $this->connect_id)){
  25. return $this->connect_id;
  26. }
  27. else{
  28. return 0;
  29. }
  30. }
  31. else{
  32. return 0;
  33. }
  34. }
  35. function drop_sequence($sequence){
  36. // This function no longer used for MySQL
  37. return 0;
  38. }
  39. function reset_sequence($sequence, $newval){
  40. // This function no longer used for MySQL
  41. return 0;
  42. }
  43. function lastid(){
  44. // This function is only used for MySQL
  45. return mysql_insert_id($this->connect_id);
  46. }
  47. function nextid($sequence) {
  48. // This function no longer used for MySQL
  49. return 0;
  50. }
  51. function close() {
  52. // Closes the database connection and frees any query results left.
  53. if ($this->query_id && is_array($this->query_id)) {
  54. while (list($key,$val)=each($this->query_id)) {
  55. mysql_free_result($val);
  56. }
  57. }
  58. $result=@mysql_close($this->connect_id);
  59. return $result;
  60. }
  61. };
  62. /************************************** QUERY ***************************/
  63. class query {
  64. var $result;
  65. var $row;
  66. function query(&$db, $query="") {
  67. // Constructor of the query object.
  68. // executes the query
  69. if(!empty($query) && !empty($db->connect_id)){
  70. // mysql_select_db($db->database, $db->connect_id); // If you are having trouble with other apps uncomment this line.
  71. $this->result=@mysql_query($query, $db->connect_id);
  72. return $this->result;
  73. }
  74. }
  75. function getrow() {
  76. $row=0;
  77. $row=@mysql_fetch_array($this->result, MYSQL_ASSOC);
  78. $this->row=$row;
  79. return $row;
  80. }
  81. function numrows() {
  82. // Gets the number of rows returned in the query
  83. $result=@mysql_num_rows($this->result);
  84. return $result;
  85. }
  86. function error() {
  87. // Gets the last error message reported for this query
  88. $result=@mysql_error();
  89. return $result;
  90. }
  91. function field($field, $row="-1") {
  92. // get the value of the field with name $field
  93. // in the current row or in row $row if supplied
  94. if($row!=-1){
  95. $result=@mysql_result($this->result, $row, $field);
  96. }
  97. else{
  98. $result=$this->row[$field];
  99. }
  100. if(isset($result)){
  101. return $result;
  102. }
  103. else{
  104. return '0';
  105. }
  106. }
  107. function firstrow() {
  108. // return the current row pointer to the first row
  109. // (CAUTION: other versions may execute the query again!! (e.g. for oracle))
  110. $result=@mysql_data_seek($this->result,0);
  111. if($result){
  112. $result=$this->getrow();
  113. return $this->row;
  114. }
  115. else{
  116. return 0;
  117. }
  118. }
  119. function seek($row){
  120. mysql_data_seek($this->result, $row);
  121. }
  122. function free() {
  123. // free the mysql result tables
  124. return mysql_free_result($this->result);
  125. }
  126. }; // End class
  127. // Custom Create Table Section
  128. function create_table(&$DB, $table, $table_name){
  129. global $q;
  130. switch($table){
  131. case "main":
  132. $sSQL="CREATE TABLE $table_name (
  133. id int unsigned DEFAULT '0' NOT NULL,
  134. datestamp datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
  135. thread int unsigned DEFAULT '0' NOT NULL,
  136. parent int unsigned DEFAULT '0' NOT NULL,
  137. author char(37) DEFAULT '' NOT NULL,
  138. subject char(255) DEFAULT '' NOT NULL,
  139. email char(200) DEFAULT '' NOT NULL,
  140. host char(50) DEFAULT '' NOT NULL,
  141. email_reply char(1) NOT NULL DEFAULT 'N',
  142. approved char(1) NOT NULL DEFAULT 'N',
  143. msgid char(100) DEFAULT '' NOT NULL,
  144. modifystamp int unsigned DEFAULT '0' NOT NULL,
  145. userid char(25) NOT NULL,
  146. PRIMARY KEY (id),
  147. KEY author (author),
  148. KEY userid (userid),
  149. KEY datestamp (datestamp),
  150. KEY subject (subject),
  151. KEY thread (thread),
  152. KEY parent (parent),
  153. KEY approved (approved),
  154. KEY msgid (msgid),
  155. KEY modifystamp (modifystamp)
  156. )";
  157. $q->query($DB, $sSQL);
  158. if(!$q->error()){
  159. $sSQL="CREATE TABLE ".$table_name."_bodies (id int unsigned DEFAULT '0' NOT NULL AUTO_INCREMENT, body text DEFAULT '' NOT NULL, thread int unsigned DEFAULT '0' NOT NULL, PRIMARY KEY (id), KEY thread (thread))";
  160. $q->query($DB, $sSQL);
  161. if($q->error()){
  162. $errormsg = $q->error();
  163. $sSQL="DROP TABLE ".$table_name;
  164. $q->query($DB, $sSQL);
  165. return $errormsg;
  166. } else {
  167. return "";
  168. }
  169. } else {
  170. return $q->error();
  171. }
  172. break;
  173. case "forums":
  174. $sSQL="CREATE TABLE ".$table_name." (
  175. id int unsigned DEFAULT 0 NOT NULL AUTO_INCREMENT,
  176. name char(50) DEFAULT '' NOT NULL,
  177. active smallint DEFAULT 0 NOT NULL,
  178. description char(255) DEFAULT '' NOT NULL,
  179. config_suffix char(50) DEFAULT '' NOT NULL,
  180. folder char(1) DEFAULT '0' NOT NULL,
  181. parent int unsigned DEFAULT 0 NOT NULL,
  182. display int unsigned DEFAULT 0 NOT NULL,
  183. table_name char(50) DEFAULT '' NOT NULL,
  184. moderation char(1) DEFAULT 'n' NOT NULL,
  185. email_list char(50) DEFAULT '' NOT NULL,
  186. email_return char(50) DEFAULT '' NOT NULL,
  187. email_tag char(50) DEFAULT '' NOT NULL,
  188. check_dup smallint unsigned DEFAULT 0 NOT NULL,
  189. multi_level smallint unsigned DEFAULT 0 NOT NULL,
  190. collapse smallint unsigned DEFAULT 0 NOT NULL,
  191. flat smallint unsigned DEFAULT 0 NOT NULL,
  192. lang char(50) DEFAULT '' NOT NULL,
  193. html char(40) DEFAULT 'N' NOT NULL,
  194. table_width char(4) DEFAULT '' NOT NULL,
  195. table_header_color char(7) DEFAULT '' NOT NULL,
  196. table_header_font_color char(7) DEFAULT '' NOT NULL,
  197. table_body_color_1 char(7) DEFAULT '' NOT NULL,
  198. table_body_color_2 char(7) DEFAULT '' NOT NULL,
  199. table_body_font_color_1 char(7) DEFAULT '' NOT NULL,
  200. table_body_font_color_2 char(7) DEFAULT '' NOT NULL,
  201. nav_color char(7) DEFAULT '' NOT NULL,
  202. nav_font_color char(7) DEFAULT '' NOT NULL,
  203. allow_uploads char(1) DEFAULT 'N' NOT NULL,
  204. upload_types char(100) DEFAULT '' NOT NULL,
  205. upload_size int unsigned DEFAULT '0' NOT NULL,
  206. max_uploads int unsigned DEFAULT '0' NOT NULL,
  207. security int unsigned DEFAULT '0' NOT NULL,
  208. showip smallint unsigned DEFAULT 1 NOT NULL,
  209. emailnotification smallint unsigned DEFAULT 1 NOT NULL,
  210. body_color char(7) DEFAULT '' NOT NULL,
  211. body_link_color char(7) DEFAULT '' NOT NULL,
  212. body_alink_color char(7) DEFAULT '' NOT NULL,
  213. body_vlink_color char(7) DEFAULT '' NOT NULL,
  214. PRIMARY KEY (id),
  215. KEY (name),
  216. KEY (active),
  217. KEY (parent),
  218. key (security) )";
  219. $q->query($DB, $sSQL);
  220. $ret=$q->error();
  221. return $ret;
  222. break;
  223. /*
  224. case "auth":
  225. // auth table
  226. $sSQL="CREATE TABLE ".$table_name."_auth (
  227. id char(25) NOT NULL,
  228. sess_id varchar(32) DEFAULT '' NOT NULL,
  229. name varchar(50) DEFAULT '' NOT NULL,
  230. username varchar(50) DEFAULT '' NOT NULL,
  231. password varchar(50) DEFAULT '' NOT NULL,
  232. email varchar(200) DEFAULT '' NOT NULL,
  233. webpage varchar(200) DEFAULT '' NOT NULL,
  234. image varchar(200) DEFAULT '' NOT NULL,
  235. icq varchar(50) DEFAULT '' NOT NULL,
  236. aol varchar(50) DEFAULT '' NOT NULL,
  237. yahoo varchar(50) DEFAULT '' NOT NULL,
  238. msn varchar(50) DEFAULT '' NOT NULL,
  239. jabber varchar(50) DEFAULT '' NOT NULL,
  240. signature varchar(255) DEFAULT '' NOT NULL,
  241. PRIMARY KEY (id),
  242. KEY (name),
  243. KEY (username),
  244. key (sess_id),
  245. key (password)
  246. )";
  247. $q->query($DB, $sSQL);
  248. $ret=$q->error();
  249. return $ret;
  250. break;
  251. */
  252. case "moderators":
  253. // moderator xref
  254. $sSQL="CREATE TABLE ".$table_name."_moderators (
  255. user_id char(25) NOT NULL,
  256. forum_id int unsigned DEFAULT 0 NOT NULL,
  257. PRIMARY KEY (user_id,forum_id),
  258. key (forum_id)
  259. )";
  260. $q->query($DB, $sSQL);
  261. $ret=$q->error();
  262. return $ret;
  263. break;
  264. case "attachments":
  265. $sSQL="CREATE TABLE IF NOT EXISTS ".$table_name." (
  266. id int unsigned DEFAULT 0 NOT NULL AUTO_INCREMENT,
  267. message_id int unsigned DEFAULT '0' NOT NULL,
  268. filename char(50) DEFAULT '' NOT NULL,
  269. PRIMARY KEY (id, message_id),
  270. KEY lookup (message_id)
  271. )";
  272. $q->query($DB, $sSQL);
  273. return $q->error();
  274. break;
  275. }
  276. }
  277. ?>