PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/forum/db/mysql.php

https://bitbucket.org/matthewsomerville/publicwhip-v1
PHP | 335 lines | 284 code | 19 blank | 32 comment | 39 complexity | c96022db3d3e4a772fb5a922f63ce702 MD5 | raw file
Possible License(s): AGPL-1.0, BSD-3-Clause
  1. <?php
  2. /***************************************************************************
  3. * mysql.php
  4. * -------------------
  5. * begin : Saturday, Feb 13, 2001
  6. * copyright : (C) 2001 The phpBB Group
  7. * email : support@phpbb.com
  8. *
  9. * $Id: mysql.php,v 1.2 2007/05/20 04:49:32 publicwhip Exp $
  10. *
  11. ***************************************************************************/
  12. /***************************************************************************
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. ***************************************************************************/
  20. if(!defined("SQL_LAYER"))
  21. {
  22. define("SQL_LAYER","mysql");
  23. class sql_db
  24. {
  25. var $db_connect_id;
  26. var $query_result;
  27. var $row = array();
  28. var $rowset = array();
  29. var $num_queries = 0;
  30. //
  31. // Constructor
  32. //
  33. function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
  34. {
  35. $this->persistency = $persistency;
  36. $this->user = $sqluser;
  37. $this->password = $sqlpassword;
  38. $this->server = $sqlserver;
  39. $this->dbname = $database;
  40. if($this->persistency)
  41. {
  42. $this->db_connect_id = @mysql_pconnect($this->server, $this->user, $this->password);
  43. }
  44. else
  45. {
  46. $this->db_connect_id = @mysql_connect($this->server, $this->user, $this->password);
  47. }
  48. if($this->db_connect_id)
  49. {
  50. if($database != "")
  51. {
  52. $this->dbname = $database;
  53. $dbselect = @mysql_select_db($this->dbname);
  54. if(!$dbselect)
  55. {
  56. @mysql_close($this->db_connect_id);
  57. $this->db_connect_id = $dbselect;
  58. }
  59. }
  60. return $this->db_connect_id;
  61. }
  62. else
  63. {
  64. return false;
  65. }
  66. }
  67. //
  68. // Other base methods
  69. //
  70. function sql_close()
  71. {
  72. if($this->db_connect_id)
  73. {
  74. if($this->query_result)
  75. {
  76. #@mysql_free_result($this->query_result); # gave warnings
  77. }
  78. $result = @mysql_close($this->db_connect_id);
  79. return $result;
  80. }
  81. else
  82. {
  83. return false;
  84. }
  85. }
  86. //
  87. // Base query method
  88. //
  89. function sql_query($query = "", $transaction = FALSE)
  90. {
  91. // Remove any pre-existing queries
  92. unset($this->query_result);
  93. if($query != "")
  94. {
  95. $this->num_queries++;
  96. $this->query_result = @mysql_query($query, $this->db_connect_id);
  97. }
  98. if($this->query_result)
  99. {
  100. unset($this->row[$this->query_result]);
  101. unset($this->rowset[$this->query_result]);
  102. return $this->query_result;
  103. }
  104. else
  105. {
  106. return ( $transaction == END_TRANSACTION ) ? true : false;
  107. }
  108. }
  109. //
  110. // Other query methods
  111. //
  112. function sql_numrows($query_id = 0)
  113. {
  114. if(!$query_id)
  115. {
  116. $query_id = $this->query_result;
  117. }
  118. if($query_id)
  119. {
  120. $result = @mysql_num_rows($query_id);
  121. return $result;
  122. }
  123. else
  124. {
  125. return false;
  126. }
  127. }
  128. function sql_affectedrows()
  129. {
  130. if($this->db_connect_id)
  131. {
  132. $result = @mysql_affected_rows($this->db_connect_id);
  133. return $result;
  134. }
  135. else
  136. {
  137. return false;
  138. }
  139. }
  140. function sql_numfields($query_id = 0)
  141. {
  142. if(!$query_id)
  143. {
  144. $query_id = $this->query_result;
  145. }
  146. if($query_id)
  147. {
  148. $result = @mysql_num_fields($query_id);
  149. return $result;
  150. }
  151. else
  152. {
  153. return false;
  154. }
  155. }
  156. function sql_fieldname($offset, $query_id = 0)
  157. {
  158. if(!$query_id)
  159. {
  160. $query_id = $this->query_result;
  161. }
  162. if($query_id)
  163. {
  164. $result = @mysql_field_name($query_id, $offset);
  165. return $result;
  166. }
  167. else
  168. {
  169. return false;
  170. }
  171. }
  172. function sql_fieldtype($offset, $query_id = 0)
  173. {
  174. if(!$query_id)
  175. {
  176. $query_id = $this->query_result;
  177. }
  178. if($query_id)
  179. {
  180. $result = @mysql_field_type($query_id, $offset);
  181. return $result;
  182. }
  183. else
  184. {
  185. return false;
  186. }
  187. }
  188. function sql_fetchrow($query_id = 0)
  189. {
  190. if(!$query_id)
  191. {
  192. $query_id = $this->query_result;
  193. }
  194. if($query_id)
  195. {
  196. $this->row[intval($query_id)] = @mysql_fetch_array($query_id);
  197. return $this->row[intval($query_id)];
  198. }
  199. else
  200. {
  201. return false;
  202. }
  203. }
  204. function sql_fetchrowset($query_id = 0)
  205. {
  206. if(!$query_id)
  207. {
  208. $query_id = $this->query_result;
  209. }
  210. if($query_id)
  211. {
  212. unset($this->rowset[intval($query_id)]);
  213. unset($this->row[intval($query_id)]);
  214. while($this->rowset[intval($query_id)] = @mysql_fetch_array($query_id))
  215. {
  216. $result[] = $this->rowset[intval($query_id)];
  217. }
  218. return $result;
  219. }
  220. else
  221. {
  222. return false;
  223. }
  224. }
  225. function sql_fetchfield($field, $rownum = -1, $query_id = 0)
  226. {
  227. if(!$query_id)
  228. {
  229. $query_id = $this->query_result;
  230. }
  231. if($query_id)
  232. {
  233. if($rownum > -1)
  234. {
  235. $result = @mysql_result($query_id, $rownum, $field);
  236. }
  237. else
  238. {
  239. if(empty($this->row[intval($query_id)]) && empty($this->rowset[intval($query_id)]))
  240. {
  241. if($this->sql_fetchrow())
  242. {
  243. $result = $this->row[intval($query_id)][$field];
  244. }
  245. }
  246. else
  247. {
  248. if($this->rowset[intval($query_id)])
  249. {
  250. $result = $this->rowset[intval($query_id)][$field];
  251. }
  252. else if($this->row[intval($query_id)])
  253. {
  254. $result = $this->row[intval($query_id)][$field];
  255. }
  256. }
  257. }
  258. return $result;
  259. }
  260. else
  261. {
  262. return false;
  263. }
  264. }
  265. function sql_rowseek($rownum, $query_id = 0){
  266. if(!$query_id)
  267. {
  268. $query_id = $this->query_result;
  269. }
  270. if($query_id)
  271. {
  272. $result = @mysql_data_seek($query_id, $rownum);
  273. return $result;
  274. }
  275. else
  276. {
  277. return false;
  278. }
  279. }
  280. function sql_nextid(){
  281. if($this->db_connect_id)
  282. {
  283. $result = @mysql_insert_id($this->db_connect_id);
  284. return $result;
  285. }
  286. else
  287. {
  288. return false;
  289. }
  290. }
  291. function sql_freeresult($query_id = 0){
  292. if(!$query_id)
  293. {
  294. $query_id = $this->query_result;
  295. }
  296. if ( $query_id )
  297. {
  298. unset($this->row[intval($query_id)]);
  299. unset($this->rowset[intval($query_id)]);
  300. @mysql_free_result($query_id);
  301. return true;
  302. }
  303. else
  304. {
  305. return false;
  306. }
  307. }
  308. function sql_error($query_id = 0)
  309. {
  310. $result["message"] = @mysql_error($this->db_connect_id);
  311. $result["code"] = @mysql_errno($this->db_connect_id);
  312. return $result;
  313. }
  314. } // class sql_db
  315. } // if ... define
  316. ?>