/!PHP/???/mysql.php
PHP | 276 lines | 134 code | 46 blank | 96 comment | 10 complexity | b616b317ff16cd32cb3c2a9f742c4317 MD5 | raw file
- <?php
- /**
- * MySQL?????????PHP4
- *
- * @version 2009?1?5?17:13:37
- * @author Zerolone
- */
-
- //class Db_MySQL{
- class Database {
- //????
- var $ResID;
-
- //????
- var $SqlStr = '';
-
- //????
- var $ResultArr = '';
-
- //????
- var $QueryCount = 0;
-
- //????
- var $QueryStr = '';
-
- //????
- var $RecordCount = 0;
-
- //??
- var $PageNum = 1;
-
- //???
- var $PageSize = 16;
-
- /**
- * ?????
- *
- */
- function __construct() {
- //??????
- if (! ($this->ResID = mysql_connect ( DB_HOST, DB_USER, DB_PASS ))) {
- $this->error_alert ( '?????', DB_HOST, '?????????' );
- } else {
- //?????
- if (! mysql_select_db ( DB_NAME, $this->ResID )) {
- error_alert ( '?????', DB_NAME, '???????' );
- }
- }
-
- //??MySQL?????
- ! version_compare ( $this->version (), '4.1', '<' ) or die ( 'MySQL???????4.1??????MySQL????' );
-
- //???????????????
- mysql_query ( 'SET NAMES "' . DB_LANG . '"' );
- }
-
- /**
- * ??????
- * @param TableName ?? ????????????????????/include/config.inc.php???????
- * @param ArrField ???? ??????????
- * @param ArrValue ???? ??????????
- *
- * @return 0??1? 0 ???? 1???
- */
- function Insert($TableName, $ArrField, $ArrValue) {
- $SqlL = 'INSERT INTO `' . DB_TABLE_PRE . $TableName . '` (';
- $SqlR = 'values (';
-
- //????
- $CountArr = count ( $ArrField );
-
- for($i = 0; $i < $CountArr - 1; $i ++) {
- $SqlL .= '`' . $ArrField [$i] . '`,';
- $SqlR .= '\'' . $ArrValue [$i] . '\',';
- }
-
- $SqlL .= '`' . $ArrField [$i] . '`)';
- $SqlR .= '\'' . $ArrValue [$i] . '\');';
-
- //??
- $this->QueryCount ++;
- $this->QueryStr .= '--?' . $this->QueryCount . '?--' . "\n";
- $this->QueryStr .= $SqlL . $SqlR . "\n";
-
- return mysql_query ( $SqlL . $SqlR );
- }
-
- /**
- * ???????id??
- *
- * @return id
- */
- function Insert_id() {
- return mysql_insert_id ( $this->ResID );
- }
-
- /**
- * ?????????
- * @param TableName ?? ?????????????????
- * @param ArrField ???? ??????????
- * @param ArrValue ???? ??????????
- * @param WhereStr ???? ??????????
- *
- * @return 0??1? 0 ???? 1???
- */
- function Update($TableName, $ArrField, $ArrValue, $WhereStr) {
- $SqlL = 'UPDATE `' . DB_TABLE_PRE . $TableName . '` SET ';
-
- //????
- $CountArr = count ( $ArrField );
-
- for($i = 0; $i < $CountArr - 1; $i ++) {
- $SqlL .= '`' . $ArrField [$i] . '`=';
- $SqlL .= '\'' . $ArrValue [$i] . '\',';
- }
-
- $SqlL .= '`' . $ArrField [$i] . '`=';
- $SqlL .= '\'' . $ArrValue [$i] . '\'';
-
- //WHERE??
- $SqlL .= ' WHERE ' . $WhereStr . ';';
-
- //??
- $this->QueryCount ++;
- $this->QueryStr .= '--?' . $this->QueryCount . '?--' . "\n";
- $this->QueryStr .= $SqlL . "\n";
-
- return mysql_query ( $SqlL );
- }
-
- /**
- * ?????????
- * @version 2008?11?13?15:15:52
- * @param TableName ?? ??????????
- * @param WhereStr ???? ??????????
- *
- * @return 0??1? 0 ???? 1???
- */
- function Delete($TableName, $WhereStr) {
- $SqlL = 'DELETE FROM `' . DB_TABLE_PRE . $TableName . '` WHERE ' . $WhereStr . ';';
-
- //??
- $this->QueryCount ++;
- $this->QueryStr .= '--?' . $this->QueryCount . '?--' . "\n";
- $this->QueryStr .= $SqlL . "\n";
-
- return mysql_query ( $SqlL );
- }
-
- /**
- * ??Sql????? ????
- * @version 2008?11?13?11:55:59
- * @param SqlStr SQL?? ??????????
- *
- */
- function Query() {
- //??
- $this->QueryCount ++;
- $this->QueryStr .= '--?' . $this->QueryCount . '?--' . "\n";
- $this->QueryStr .= $this->SqlStr . "\n";
-
- //??Sql??
- $temp_query = mysql_query ( $this->SqlStr, $this->ResID );
-
- //??????
- unset ( $this->ResultArr );
- $return_int=0;
-
- //??????
- while ( $row = mysql_fetch_array ( $temp_query ) ) {
- // print_r($row);
- // echo '<hr>';
- $this->ResultArr [] = $row;
- $return_int=1;
- }
-
- if ($return_int) {
- return TRUE;
- } else {
- return FALSE;
- }
- }
-
- /**
- * ??????
- *
- * @return ???
- */
- function version() {
- return mysql_get_server_info ( $this->ResID );
- }
-
- /**
- * ??SQL? ??
- * @version 2008?11?13?14:04:40
- * @param SqlStr SQL?? ??????????
- *
- * @return 0??1? 0 ???? 1???
- */
- function ExecuteQuery() {
- //??
- $this->QueryCount ++;
- $this->QueryStr .= '--?' . $this->QueryCount . '?--' . "\n";
- $this->QueryStr .= $this->SqlStr . "\n";
-
- //??Sql??
- return mysql_query ( $this->SqlStr, $this->ResID );
- }
-
- /**
- * ??????
- */
- function PrintDebug() {
- $variable_count = '--?????' . $this->QueryCount . "\n";
- $variable_sql = $this->QueryStr . "\n";
-
- $ThisPage = $_SERVER ['PHP_SELF'];
-
- //??????
- $variable_log = "?????_GET???:\n" . print_array ( $_GET );
- $variable_log .= "?????_POST???:\n" . print_array ( $_POST );
- $variable_log .= "?????_COOKIE???:\n" . print_array ( $_COOKIE );
- $variable_log .= "?????_SESSION???:\n" . print_array ( @$_SESSION );
-
- //IIS???? ????????????
- $variable_log .= "HTTP???:\n" . print_array ( getallheaders () );
-
- return "??????$ThisPage [<a href=\"javascript:history.go(0);\">?????</a>]
- <script language=\"javascript\" type=\"text/javascript\">
- function showdebug(span_show, span_source)
- {
- var TheImg;
- span_show = eval(span_show);
- span_source = eval(span_source)
-
- if(span_show.style.display == \"none\")
- {
- span_show.style.display = \"\";
- span_source.innerHTML = \"<font color=\'blue\'>??</font>????\";
- }
- else
- {
- span_show.style.display = \"none\";
- span_source.innerHTML = \"<font color=\'red\'>??</font>????\";
- }
- }
- </script>
- <span align=left id=debug_source onClick=showdebug('debug_show','debug_source')><font color=\"red\">??</font>????</span><br>
- <!-- <span id=debug_source onClick=showdebug('debug_show','debug_source')><font color=\"blue\">??</font>????</span><br> -->
- <div align=\"left\"><span id=debug_show style=\"display=none\">
- <textarea style='width=800;height=500' cols='100' rows='8'>$variable_count$variable_sql$variable_log</textarea>
- </span>
- </div>
- ";
- }
-
- /**
- * ????
- * @param $ImagePath ????
- * @param $ImageUrl ?
- * @param String ????
- */
- function error_alert($Type, $Source, $Message) {
- $ThisPage = $_SERVER ['PHP_SELF'];
-
- $x = "
- ?????????<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>
- <br>????? ($Source) $Message
- <hr color=blue size=1 width=100% align=left>
- ";
- echo $x;
- }
-
- }
-
- ?>