Просмотр файла db/mysql4.php

Размер файла: 5.65Kb
  1. <?php
  2.  
  3. if ( !defined('IN_PHPBB') )
  4. {
  5. die("ERROR!!! THIS FILE PROTECTED. IF YOU SAW THIS REPORT, MEANS HACKERS HERE IS NOTHING TO DO ");
  6. }
  7.  
  8. if(!defined("SQL_LAYER"))
  9. {
  10.  
  11. define("SQL_LAYER","mysql4");
  12.  
  13. class sql_db
  14. {
  15.  
  16. var $db_connect_id;
  17. var $query_result;
  18. var $row = array();
  19. var $rowset = array();
  20. var $num_queries = 0;
  21. var $in_transaction = 0;
  22.  
  23. //
  24. // Constructor
  25. //
  26. function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
  27. {
  28. $this->persistency = $persistency;
  29. $this->user = $sqluser;
  30. $this->password = $sqlpassword;
  31. $this->server = $sqlserver;
  32. $this->dbname = $database;
  33.  
  34. $this->db_connect_id = ($this->persistency) ? mysql_pconnect($this->server, $this->user, $this->password) : mysql_connect($this->server, $this->user, $this->password);
  35.  
  36. if( $this->db_connect_id )
  37. {
  38. if( $database != "" )
  39. {
  40. $this->dbname = $database;
  41. $dbselect = mysql_select_db($this->dbname);
  42.  
  43. if( !$dbselect )
  44. {
  45. mysql_close($this->db_connect_id);
  46. $this->db_connect_id = $dbselect;
  47. }
  48. }
  49.  
  50. return $this->db_connect_id;
  51. }
  52. else
  53. {
  54. return false;
  55. }
  56. }
  57.  
  58. //
  59. // Other base methods
  60. //
  61. function sql_close()
  62. {
  63. if( $this->db_connect_id )
  64. {
  65. //
  66. // Commit any remaining transactions
  67. //
  68. if( $this->in_transaction )
  69. {
  70. mysql_query("COMMIT", $this->db_connect_id);
  71. }
  72.  
  73. return mysql_close($this->db_connect_id);
  74. }
  75. else
  76. {
  77. return false;
  78. }
  79. }
  80.  
  81. //
  82. // Base query method
  83. //
  84. function sql_query($query = "", $transaction = FALSE)
  85. {
  86. //
  87. // Remove any pre-existing queries
  88. //
  89. unset($this->query_result);
  90.  
  91. if( $query != "" )
  92. {
  93. $this->num_queries++;
  94. if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
  95. {
  96. $result = mysql_query("BEGIN", $this->db_connect_id);
  97. if(!$result)
  98. {
  99. return false;
  100. }
  101. $this->in_transaction = TRUE;
  102. }
  103.  
  104. $this->query_result = mysql_query($query, $this->db_connect_id);
  105. }
  106. else
  107. {
  108. if( $transaction == END_TRANSACTION && $this->in_transaction )
  109. {
  110. $result = mysql_query("COMMIT", $this->db_connect_id);
  111. }
  112. }
  113.  
  114. if( $this->query_result )
  115. {
  116. unset($this->row[$this->query_result]);
  117. unset($this->rowset[$this->query_result]);
  118.  
  119. if( $transaction == END_TRANSACTION && $this->in_transaction )
  120. {
  121. $this->in_transaction = FALSE;
  122.  
  123. if ( !mysql_query("COMMIT", $this->db_connect_id) )
  124. {
  125. mysql_query("ROLLBACK", $this->db_connect_id);
  126. return false;
  127. }
  128. }
  129. return $this->query_result;
  130. }
  131. else
  132. {
  133. if( $this->in_transaction )
  134. {
  135. mysql_query("ROLLBACK", $this->db_connect_id);
  136. $this->in_transaction = FALSE;
  137. }
  138. return false;
  139. }
  140. }
  141.  
  142. //
  143. // Other query methods
  144. //
  145. function sql_numrows($query_id = 0)
  146. {
  147. if( !$query_id )
  148. {
  149. $query_id = $this->query_result;
  150. }
  151.  
  152. return ( $query_id ) ? mysql_num_rows($query_id) : false;
  153. }
  154.  
  155. function sql_affectedrows()
  156. {
  157. return ( $this->db_connect_id ) ? mysql_affected_rows($this->db_connect_id) : false;
  158. }
  159.  
  160. function sql_numfields($query_id = 0)
  161. {
  162. if( !$query_id )
  163. {
  164. $query_id = $this->query_result;
  165. }
  166.  
  167. return ( $query_id ) ? mysql_num_fields($query_id) : false;
  168. }
  169.  
  170. function sql_fieldname($offset, $query_id = 0)
  171. {
  172. if( !$query_id )
  173. {
  174. $query_id = $this->query_result;
  175. }
  176.  
  177. return ( $query_id ) ? mysql_field_name($query_id, $offset) : false;
  178. }
  179.  
  180. function sql_fieldtype($offset, $query_id = 0)
  181. {
  182. if( !$query_id )
  183. {
  184. $query_id = $this->query_result;
  185. }
  186.  
  187. return ( $query_id ) ? mysql_field_type($query_id, $offset) : false;
  188. }
  189.  
  190. function sql_fetchrow($query_id = 0)
  191. {
  192. if( !$query_id )
  193. {
  194. $query_id = $this->query_result;
  195. }
  196.  
  197. if( $query_id )
  198. {
  199. $this->row[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC);
  200. return $this->row[$query_id];
  201. }
  202. else
  203. {
  204. return false;
  205. }
  206. }
  207.  
  208. function sql_fetchrowset($query_id = 0)
  209. {
  210. if( !$query_id )
  211. {
  212. $query_id = $this->query_result;
  213. }
  214.  
  215. if( $query_id )
  216. {
  217. unset($this->rowset[$query_id]);
  218. unset($this->row[$query_id]);
  219.  
  220. while($this->rowset[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC))
  221. {
  222. $result[] = $this->rowset[$query_id];
  223. }
  224.  
  225. return $result;
  226. }
  227. else
  228. {
  229. return false;
  230. }
  231. }
  232.  
  233. function sql_fetchfield($field, $rownum = -1, $query_id = 0)
  234. {
  235. if( !$query_id )
  236. {
  237. $query_id = $this->query_result;
  238. }
  239.  
  240. if( $query_id )
  241. {
  242. if( $rownum > -1 )
  243. {
  244. $result = mysql_result($query_id, $rownum, $field);
  245. }
  246. else
  247. {
  248. if( empty($this->row[$query_id]) && empty($this->rowset[$query_id]) )
  249. {
  250. if( $this->sql_fetchrow() )
  251. {
  252. $result = $this->row[$query_id][$field];
  253. }
  254. }
  255. else
  256. {
  257. if( $this->rowset[$query_id] )
  258. {
  259. $result = $this->rowset[$query_id][0][$field];
  260. }
  261. else if( $this->row[$query_id] )
  262. {
  263. $result = $this->row[$query_id][$field];
  264. }
  265. }
  266. }
  267.  
  268. return $result;
  269. }
  270. else
  271. {
  272. return false;
  273. }
  274. }
  275.  
  276. function sql_rowseek($rownum, $query_id = 0)
  277. {
  278. if( !$query_id )
  279. {
  280. $query_id = $this->query_result;
  281. }
  282.  
  283. return ( $query_id ) ? mysql_data_seek($query_id, $rownum) : false;
  284. }
  285.  
  286. function sql_nextid()
  287. {
  288. return ( $this->db_connect_id ) ? mysql_insert_id($this->db_connect_id) : false;
  289. }
  290.  
  291. function sql_freeresult($query_id = 0)
  292. {
  293. if( !$query_id )
  294. {
  295. $query_id = $this->query_result;
  296. }
  297.  
  298. if ( $query_id )
  299. {
  300. unset($this->row[$query_id]);
  301. unset($this->rowset[$query_id]);
  302.  
  303. mysql_free_result($query_id);
  304. return true;
  305. }
  306. else
  307. {
  308. return false;
  309. }
  310. }
  311. function sql_error()
  312. {
  313. $result['message'] = @mysql_error($this->db_connect_id);
  314. $result['code'] = @mysql_errno($this->db_connect_id);
  315. return $result;
  316. }
  317. } // class sql_db
  318.  
  319. } // if ... define
  320.  
  321. ?>