PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/!PHP/???/mysql.php

http://mootoolstools.googlecode.com/
PHP | 276 lines | 134 code | 46 blank | 96 comment | 10 complexity | b616b317ff16cd32cb3c2a9f742c4317 MD5 | raw file
  1. <?php
  2. /**
  3. * MySQL?????????PHP4
  4. *
  5. * @version 2009?1?5?17:13:37
  6. * @author Zerolone
  7. */
  8. //class Db_MySQL{
  9. class Database {
  10. //????
  11. var $ResID;
  12. //????
  13. var $SqlStr = '';
  14. //????
  15. var $ResultArr = '';
  16. //????
  17. var $QueryCount = 0;
  18. //????
  19. var $QueryStr = '';
  20. //????
  21. var $RecordCount = 0;
  22. //??
  23. var $PageNum = 1;
  24. //???
  25. var $PageSize = 16;
  26. /**
  27. * ?????
  28. *
  29. */
  30. function __construct() {
  31. //??????
  32. if (! ($this->ResID = mysql_connect ( DB_HOST, DB_USER, DB_PASS ))) {
  33. $this->error_alert ( '?????', DB_HOST, '?????????' );
  34. } else {
  35. //?????
  36. if (! mysql_select_db ( DB_NAME, $this->ResID )) {
  37. error_alert ( '?????', DB_NAME, '???????' );
  38. }
  39. }
  40. //??MySQL?????
  41. ! version_compare ( $this->version (), '4.1', '<' ) or die ( 'MySQL???????4.1??????MySQL????' );
  42. //???????????????
  43. mysql_query ( 'SET NAMES "' . DB_LANG . '"' );
  44. }
  45. /**
  46. * ??????
  47. * @param TableName ?? ????????????????????/include/config.inc.php???????
  48. * @param ArrField ???? ??????????
  49. * @param ArrValue ???? ??????????
  50. *
  51. * @return 0??1? 0 ???? 1???
  52. */
  53. function Insert($TableName, $ArrField, $ArrValue) {
  54. $SqlL = 'INSERT INTO `' . DB_TABLE_PRE . $TableName . '` (';
  55. $SqlR = 'values (';
  56. //????
  57. $CountArr = count ( $ArrField );
  58. for($i = 0; $i < $CountArr - 1; $i ++) {
  59. $SqlL .= '`' . $ArrField [$i] . '`,';
  60. $SqlR .= '\'' . $ArrValue [$i] . '\',';
  61. }
  62. $SqlL .= '`' . $ArrField [$i] . '`)';
  63. $SqlR .= '\'' . $ArrValue [$i] . '\');';
  64. //??
  65. $this->QueryCount ++;
  66. $this->QueryStr .= '--?' . $this->QueryCount . '?--' . "\n";
  67. $this->QueryStr .= $SqlL . $SqlR . "\n";
  68. return mysql_query ( $SqlL . $SqlR );
  69. }
  70. /**
  71. * ???????id??
  72. *
  73. * @return id
  74. */
  75. function Insert_id() {
  76. return mysql_insert_id ( $this->ResID );
  77. }
  78. /**
  79. * ?????????
  80. * @param TableName ?? ?????????????????
  81. * @param ArrField ???? ??????????
  82. * @param ArrValue ???? ??????????
  83. * @param WhereStr ???? ??????????
  84. *
  85. * @return 0??1? 0 ???? 1???
  86. */
  87. function Update($TableName, $ArrField, $ArrValue, $WhereStr) {
  88. $SqlL = 'UPDATE `' . DB_TABLE_PRE . $TableName . '` SET ';
  89. //????
  90. $CountArr = count ( $ArrField );
  91. for($i = 0; $i < $CountArr - 1; $i ++) {
  92. $SqlL .= '`' . $ArrField [$i] . '`=';
  93. $SqlL .= '\'' . $ArrValue [$i] . '\',';
  94. }
  95. $SqlL .= '`' . $ArrField [$i] . '`=';
  96. $SqlL .= '\'' . $ArrValue [$i] . '\'';
  97. //WHERE??
  98. $SqlL .= ' WHERE ' . $WhereStr . ';';
  99. //??
  100. $this->QueryCount ++;
  101. $this->QueryStr .= '--?' . $this->QueryCount . '?--' . "\n";
  102. $this->QueryStr .= $SqlL . "\n";
  103. return mysql_query ( $SqlL );
  104. }
  105. /**
  106. * ?????????
  107. * @version 2008?11?13?15:15:52
  108. * @param TableName ?? ??????????
  109. * @param WhereStr ???? ??????????
  110. *
  111. * @return 0??1? 0 ???? 1???
  112. */
  113. function Delete($TableName, $WhereStr) {
  114. $SqlL = 'DELETE FROM `' . DB_TABLE_PRE . $TableName . '` WHERE ' . $WhereStr . ';';
  115. //??
  116. $this->QueryCount ++;
  117. $this->QueryStr .= '--?' . $this->QueryCount . '?--' . "\n";
  118. $this->QueryStr .= $SqlL . "\n";
  119. return mysql_query ( $SqlL );
  120. }
  121. /**
  122. * ??Sql????? ????
  123. * @version 2008?11?13?11:55:59
  124. * @param SqlStr SQL?? ??????????
  125. *
  126. */
  127. function Query() {
  128. //??
  129. $this->QueryCount ++;
  130. $this->QueryStr .= '--?' . $this->QueryCount . '?--' . "\n";
  131. $this->QueryStr .= $this->SqlStr . "\n";
  132. //??Sql??
  133. $temp_query = mysql_query ( $this->SqlStr, $this->ResID );
  134. //??????
  135. unset ( $this->ResultArr );
  136. $return_int=0;
  137. //??????
  138. while ( $row = mysql_fetch_array ( $temp_query ) ) {
  139. // print_r($row);
  140. // echo '<hr>';
  141. $this->ResultArr [] = $row;
  142. $return_int=1;
  143. }
  144. if ($return_int) {
  145. return TRUE;
  146. } else {
  147. return FALSE;
  148. }
  149. }
  150. /**
  151. * ??????
  152. *
  153. * @return ???
  154. */
  155. function version() {
  156. return mysql_get_server_info ( $this->ResID );
  157. }
  158. /**
  159. * ??SQL? ??
  160. * @version 2008?11?13?14:04:40
  161. * @param SqlStr SQL?? ??????????
  162. *
  163. * @return 0??1? 0 ???? 1???
  164. */
  165. function ExecuteQuery() {
  166. //??
  167. $this->QueryCount ++;
  168. $this->QueryStr .= '--?' . $this->QueryCount . '?--' . "\n";
  169. $this->QueryStr .= $this->SqlStr . "\n";
  170. //??Sql??
  171. return mysql_query ( $this->SqlStr, $this->ResID );
  172. }
  173. /**
  174. * ??????
  175. */
  176. function PrintDebug() {
  177. $variable_count = '--?????' . $this->QueryCount . "\n";
  178. $variable_sql = $this->QueryStr . "\n";
  179. $ThisPage = $_SERVER ['PHP_SELF'];
  180. //??????
  181. $variable_log = "?????_GET???:\n" . print_array ( $_GET );
  182. $variable_log .= "?????_POST???:\n" . print_array ( $_POST );
  183. $variable_log .= "?????_COOKIE???:\n" . print_array ( $_COOKIE );
  184. $variable_log .= "?????_SESSION???:\n" . print_array ( @$_SESSION );
  185. //IIS???? ????????????
  186. $variable_log .= "HTTP???:\n" . print_array ( getallheaders () );
  187. return "??????$ThisPage [<a href=\"javascript:history.go(0);\">?????</a>]
  188. <script language=\"javascript\" type=\"text/javascript\">
  189. function showdebug(span_show, span_source)
  190. {
  191. var TheImg;
  192. span_show = eval(span_show);
  193. span_source = eval(span_source)
  194. if(span_show.style.display == \"none\")
  195. {
  196. span_show.style.display = \"\";
  197. span_source.innerHTML = \"<font color=\'blue\'>??</font>????\";
  198. }
  199. else
  200. {
  201. span_show.style.display = \"none\";
  202. span_source.innerHTML = \"<font color=\'red\'>??</font>????\";
  203. }
  204. }
  205. </script>
  206. <span align=left id=debug_source onClick=showdebug('debug_show','debug_source')><font color=\"red\">??</font>????</span><br>
  207. <!-- <span id=debug_source onClick=showdebug('debug_show','debug_source')><font color=\"blue\">??</font>????</span><br> -->
  208. <div align=\"left\"><span id=debug_show style=\"display=none\">
  209. <textarea style='width=800;height=500' cols='100' rows='8'>$variable_count$variable_sql$variable_log</textarea>
  210. </span>
  211. </div>
  212. ";
  213. }
  214. /**
  215. * ????
  216. * @param $ImagePath ????
  217. * @param $ImageUrl ?
  218. * @param String ????
  219. */
  220. function error_alert($Type, $Source, $Message) {
  221. $ThisPage = $_SERVER ['PHP_SELF'];
  222. $x = "
  223. ?????????<font color=red>$Type</font>?<a href=\"javascript:history.go(0);\">?????</a>??<a href=\"report_error_page.php?Page=$ThisPage&Source=$Source&Message=$Message\" target=_blank>??????? ??????????</a>?<br>
  224. <br>????? ($Source) $Message
  225. <hr color=blue size=1 width=100% align=left>
  226. ";
  227. echo $x;
  228. }
  229. }
  230. ?>