⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysql.php

📁 泛微协同办公系统标准版E-office V5.5的源代码内含泛微办公系统V5.5自动注册文件。
💻 PHP
字号:
<?php

class db_driver
{

	var $obj = array
	(
		"sql_database" => "",
		"sql_user" => "root",
		"sql_pass" => "",
		"sql_host" => "localhost",
		"sql_port" => "",
		"persistent" => "0",
		"sql_tbl_prefix" => "ibf_",
		"cached_queries" => array( ),
		"debug" => 0
	);
	var $query_id = "";
	var $connection_id = "";
	var $query_count = 0;
	var $record_row = array( );
	var $return_die = 0;
	var $error = "";

	function connect( )
	{
		if ( $this->obj['persistent'] )
		{
			$this->connection_id = mysql_pconnect( $this->obj['sql_host'], $this->obj['sql_user'], $this->obj['sql_pass'] );
		}
		else
		{
			$this->connection_id = mysql_connect( $this->obj['sql_host'], $this->obj['sql_user'], $this->obj['sql_pass'] );
		}
		if ( !mysql_select_db( $this->obj['sql_database'], $this->connection_id ) )
		{
			echo "ERROR: Cannot find database ".$this->obj['sql_database'];
		}
	}

	function query( $the_query, $bypass = 0 )
	{
		if ( $bypass != 1 && $this->obj['sql_tbl_prefix'] != "ibf_" )
		{
			$the_query = preg_replace( "/ibf_(\\S+?)([\\s\\.,]|\$)/", $this->obj['sql_tbl_prefix']."\\1\\2", $the_query );
		}
		if ( $this->obj['debug'] )
		{
			global $Debug;
			global $ibforums;
			$Debug->starttimer( );
		}
		$this->query_id = mysql_query( $the_query, $this->connection_id );
		if ( !$this->query_id )
		{
			$this->fatal_error( "mySQL query error: {$the_query}" );
		}
		if ( $this->obj['debug'] )
		{
			$endtime = $Debug->endtimer( );
			if ( preg_match( "/^select/i", $the_query ) )
			{
				$eid = mysql_query( "EXPLAIN {$the_query}", $this->connection_id );
				$ibforums->debug_html .= "<table width='95%' border='1' cellpadding='6' cellspacing='0' bgcolor='#FFE8F3' align='center'>\r\n\t\t\t\t\t\t\t\t\t\t   <tr>\r\n\t\t\t\t\t\t\t\t\t\t   \t <td colspan='8' style='font-size:14px' bgcolor='#FFC5Cb'><b>Select Query</b></td>\r\n\t\t\t\t\t\t\t\t\t\t   </tr>\r\n\t\t\t\t\t\t\t\t\t\t   <tr>\r\n\t\t\t\t\t\t\t\t\t\t    <td colspan='8' style='font-family:courier new, courier, monaco, arial;font-size:14px'>{$the_query}</td>\r\n\t\t\t\t\t\t\t\t\t\t   </tr>\r\n\t\t\t\t\t\t\t\t\t\t   <tr bgcolor='#FFC5Cb'>\r\n\t\t\t\t\t\t\t\t\t\t\t <td><b>table</b></td><td><b>type</b></td><td><b>possible_keys</b></td>\r\n\t\t\t\t\t\t\t\t\t\t\t <td><b>key</b></td><td><b>key_len</b></td><td><b>ref</b></td>\r\n\t\t\t\t\t\t\t\t\t\t\t <td><b>rows</b></td><td><b>Extra</b></td>\r\n\t\t\t\t\t\t\t\t\t\t   </tr>\n";
				while ( $array = mysql_fetch_array( $eid ) )
				{
					$type_col = "#FFFFFF";
					if ( $array['type'] == "ref" || $array['type'] == "eq_ref" || $array['type'] == "const" )
					{
						$type_col = "#D8FFD4";
					}
					else if ( $array['type'] == "ALL" )
					{
						$type_col = "#FFEEBA";
					}
					$ibforums->debug_html .= "<tr bgcolor='#FFFFFF'>\r\n\t\t\t\t\t\t\t\t\t\t\t <td>{$array['table']}&nbsp;</td>\r\n\t\t\t\t\t\t\t\t\t\t\t <td bgcolor='{$type_col}'>{$array['type']}&nbsp;</td>\r\n\t\t\t\t\t\t\t\t\t\t\t <td>{$array['possible_keys']}&nbsp;</td>\r\n\t\t\t\t\t\t\t\t\t\t\t <td>{$array['key']}&nbsp;</td>\r\n\t\t\t\t\t\t\t\t\t\t\t <td>{$array['key_len']}&nbsp;</td>\r\n\t\t\t\t\t\t\t\t\t\t\t <td>{$array['ref']}&nbsp;</td>\r\n\t\t\t\t\t\t\t\t\t\t\t <td>{$array['rows']}&nbsp;</td>\r\n\t\t\t\t\t\t\t\t\t\t\t <td>{$array['Extra']}&nbsp;</td>\r\n\t\t\t\t\t\t\t\t\t\t   </tr>\n";
				}
				if ( 0.1 < $endtime )
				{
					$endtime = "<span style='color:red'><b>{$endtime}</b></span>";
				}
				$ibforums->debug_html .= "<tr>\r\n\t\t\t\t\t\t\t\t\t\t  <td colspan='8' bgcolor='#FFD6DC' style='font-size:14px'><b>mySQL time</b>: {$endtime}</b></td>\r\n\t\t\t\t\t\t\t\t\t\t  </tr>\r\n\t\t\t\t\t\t\t\t\t\t  </table>\n<br />\n";
			}
			else
			{
				$ibforums->debug_html .= "<table width='95%' border='1' cellpadding='6' cellspacing='0' bgcolor='#FEFEFE'  align='center'>\r\n\t\t\t\t\t\t\t\t\t\t <tr>\r\n\t\t\t\t\t\t\t\t\t\t  <td style='font-size:14px' bgcolor='#EFEFEF'><b>Non Select Query</b></td>\r\n\t\t\t\t\t\t\t\t\t\t </tr>\r\n\t\t\t\t\t\t\t\t\t\t <tr>\r\n\t\t\t\t\t\t\t\t\t\t  <td style='font-family:courier new, courier, monaco, arial;font-size:14px'>{$the_query}</td>\r\n\t\t\t\t\t\t\t\t\t\t </tr>\r\n\t\t\t\t\t\t\t\t\t\t <tr>\r\n\t\t\t\t\t\t\t\t\t\t  <td style='font-size:14px' bgcolor='#EFEFEF'><b>mySQL time</b>: {$endtime}</span></td>\r\n\t\t\t\t\t\t\t\t\t\t </tr>\r\n\t\t\t\t\t\t\t\t\t\t</table><br />\n\n";
			}
		}
		++$this->query_count;
		$this->obj['cached_queries'][] = $the_query;
		return $this->query_id;
	}

	function fetch_row( $query_id = "" )
	{
		if ( $query_id == "" )
		{
			$query_id = $this->query_id;
		}
		$this->record_row = mysql_fetch_array( $query_id, MYSQL_ASSOC );
		return $this->record_row;
	}

	function get_affected_rows( )
	{
		return mysql_affected_rows( $this->connection_id );
	}

	function get_num_rows( )
	{
		return mysql_num_rows( $this->query_id );
	}

	function get_insert_id( )
	{
		return mysql_insert_id( $this->connection_id );
	}

	function get_query_cnt( )
	{
		return $this->query_count;
	}

	function free_result( $query_id = "" )
	{
		if ( $query_id == "" )
		{
			$query_id = $this->query_id;
		}
		@mysql_free_result( $query_id );
	}

	function close_db( )
	{
		return mysql_close( $this->connection_id );
	}

	function get_table_names( )
	{
		$result = mysql_list_tables( $this->obj['sql_database'] );
		$num_tables = @mysql_numrows( $result );
		$i = 0;
		for ( ;	$i < $num_tables;	++$i	)
		{
			$tables[] = mysql_tablename( $result, $i );
		}
		mysql_free_result( $result );
		return $tables;
	}

	function get_result_fields( $query_id = "" )
	{
		if ( $query_id == "" )
		{
			$query_id = $this->query_id;
		}
		while ( $field = mysql_fetch_field( $query_id ) )
		{
			$Fields[] = $field;
		}
		return $Fields;
	}

	function fatal_error( $the_error )
	{
		global $INFO;
		if ( $this->return_die == 1 )
		{
			$this->error = mysql_error( );
			return TRUE;
		}
		$the_error .= "\n\nmySQL error: ".mysql_error( )."\n";
		$the_error .= "mySQL error code: ".mysql_errno( )."\n";
		$the_error .= "Date: ".date( "l dS of F Y h:i:s A" );
		$out = "<html><head><title>华酷论坛数据库错误信息</title>\r\n    \t\t   <style>P,BODY{ font-family:arial,sans-serif; font-size:12px; }</style></head><body>\r\n    \t\t   &nbsp;<br><br><blockquote><b>{$INFO['board_name']} 数据库出现了错误。</b><br>\r\n    \t\t   请按下面的链接刷新页面 [<a href=\"javascript:window.location=window.location;\">刷新</a>], 如果问题还是没有得到解决,请点击下面的链接联系论坛管理员 [<a href='mailto:{$INFO['email_in']}?subject=SQL+Error'>联系管理员</a>]\r\n    \t\t   <br><br><b>错误信息</b><br>\r\n    \t\t   <form name='mysql'><textarea rows=\"15\" cols=\"60\">".htmlspecialchars( $the_error )."</textarea></form><br>对于论坛的错误给您带来的不便,我们向你表示诚挚的歉意!</blockquote></body></html>";
		echo $out;
		exit( "" );
	}

	function compile_db_insert_string( $data )
	{
		$field_names = "";
		$field_values = "";
		foreach ( $data as $k => $v )
		{
			$v = preg_replace( "/'/", "\\'", $v );
			$field_names .= "{$k},";
			$field_values .= "'{$v}',";
		}
		$field_names = preg_replace( "/,\$/", "", $field_names );
		$field_values = preg_replace( "/,\$/", "", $field_values );
		return array(
			"FIELD_NAMES" => $field_names,
			"FIELD_VALUES" => $field_values
		);
	}

	function compile_db_update_string( $data )
	{
		$return_string = "";
		foreach ( $data as $k => $v )
		{
			$v = preg_replace( "/'/", "\\'", $v );
			$return_string .= $k."='".$v."',";
		}
		$return_string = preg_replace( "/,\$/", "", $return_string );
		return $return_string;
	}

}

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -