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

📄 database.php

📁 网络硬盘_支持1GB文件上传和续传_无错版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
			if ($key) {				$array[ $row[$key] ] = $row;			} else {				$array[] = $row;			}		}		mysql_free_result( $cur );		return $array;	}    function loadRowList2( $key='',$from='',$limit='' ) {		/*if (!($cur = $this->query())) {			return null;		}*/        $cur= $this->_cursor;		$array = array();$i=0;		while ($row = mysql_fetch_assoc( $cur )) {            $i++; if($limit&&($i<$from+1||$i>$from+$limit)) continue;            if($limit&&($i>$from+$limit)) break;			if ($key) {				$array[ $row[$key] ] = $row;			} else {				$array[] = $row;			}		}		mysql_free_result( $cur );		return $array;	}	/**	* Document::db_insertObject()	*	* { Description }	*	* @param [type] $keyName	* @param [type] $verbose	*/	function insertObject( $table, &$object, $keyName = NULL, $verbose=false ) {		$fmtsql = "INSERT INTO $table ( %s ) VALUES ( %s ) ";		foreach (get_object_vars( $object ) as $k => $v) {			//if (is_array($v) or is_object($v) or $v == NULL) {            if (is_array($v) or is_object($v)) {				continue;			}			if ($k[0] == '_') { // internal field			continue;			}			$fields[] = "`$k`";			$values[] = "'" . $this->getEscaped( $v ) . "'";		}		$this->setQuery( sprintf( $fmtsql, implode( ",", $fields ) ,  implode( ",", $values ) ) );		($verbose) && print "$sql<br />\n";		if (!$this->query()) {			return false;		}		$id = mysql_insert_id();		($verbose) && print "id=[$id]<br />\n";		if ($keyName && $id) {			$object->$keyName = $id;		}		return true;	}	/**	* Document::db_updateObject()	*	* { Description }	*	* @param [type] $updateNulls	*/	function updateObject( $table, &$object, $keyName, $updateNulls=true ) {		$fmtsql = "UPDATE $table SET %s WHERE %s";		foreach (get_object_vars( $object ) as $k => $v) {			if( is_array($v) or is_object($v) or $k[0] == '_' ) { // internal or NA field			continue;			}			if( $k == $keyName ) { // PK not to be updated			$where = "$keyName='" . $this->getEscaped( $v ) . "'";			continue;			}			if ($v === NULL && !$updateNulls) {				continue;			}			//if( $v == '' ) {			//	$val = "''";			//} else {				$val = "'" . $this->getEscaped( $v ) . "'";			//}			$tmp[] = "`$k`=$val";		}        $s=  get_object_vars( $object );		$this->setQuery( sprintf( $fmtsql, implode( ",", $tmp ) , $where ) );        return $this->query();	}	/**	* @param boolean If TRUE, displays the last SQL statement sent to the database	* @return string A standised error message	*/	function stderr( $showSQL = false ) {		return "DB function failed with error number $this->_errorNum"		."<br /><font color=\"red\">$this->_errorMsg</font>"		.($showSQL ? "<br />SQL = <pre>$this->_sql</pre>" : '');	}	function insertid()	{		return mysql_insert_id();	}	function getVersion()	{		return mysql_get_server_info();	}    /*========================================================================*/    // Return an array of tables    /*========================================================================*/    function get_table_names() {		$result     = mysql_list_tables($this->_db);		$num_tables = @mysql_numrows($result);		for ($i = 0; $i < $num_tables; $i++)		{			$tables[] = mysql_tablename($result, $i);		}		mysql_free_result($result);		return $tables;   	}   	/*========================================================================*/    // Return an array of fields    /*========================================================================*/    function get_result_fields( $cur=null )    {		while ($field = mysql_fetch_field( $cur ? $cur : $this->_cursor ))		{            $Fields[$field['name']] = $field;		}        //mysql_free_result(  $cur ? $cur : $this->_cursor  );		return $Fields;   	}    /*========================================================================*/    // Return an array of table fields    /*========================================================================*/    function get_table_fields( $table, $cur=null )    {        $this->setQuery("SHOW COLUMNS FROM $table");        $this->query();        $Fields=$this->loadRowList();        foreach($Fields as $Field)        {            $Fields2[$Field[Field]]=$Field;        }		return $Fields2;   	}	/*========================================================================*/    // Test to see if a field exists by forcing and trapping an error.    // It ain't pretty, but it do the job don't it, eh?    // Posh my ass.    // Return 1 for exists, 0 for not exists and jello for the naked guy    // Fun fact: The number of times I spelt 'field' as 'feild'in this part: 104    /*========================================================================*/    function field_exists($field, $table)    {        $$this->setQuery("SELECT COUNT($field) as count FROM $table");        $this->query();		return $this->getNumRows();	}    /*========================================================================*/    // Shut down the database    /*========================================================================*/    function close_db() {        return mysql_close( $this->_resource );    }    //function build}/*+--------------------------------------------------------------------------|   YABLinks Directory v1.1|   ========================================|   by Stephen Yabziz|   (c) 2005 YABSoft Services|   http://www.yabsoft.com|   ========================================|   Web: http://www.yabsoft.com|   Time: Wed, 28 Mar 2005 17:09:21 GMT|   Email: ywyhnchina@163.com+---------------------------------------------------------------------------||   > Script written by Stephen Yabziz|   > Date started: 14th February 2004|   > Some great function writen by me:)|+--------------------------------------------------------------------------*/class TABLE{    var $_db;    var $_tbl;    var $_tbl_key;    var $_err_msg;    function TABLE($db,$tbl,$key){        $this->_db=$db;        $this->_tbl=$tbl;        $this->_tbl_key=$key;    }    function insert(){        $this->_db->insertObject($this->_tbl,$this,"",false);        $this->setErr($this->_db->getErrorMsg());    }    function update(){        $this->_db->updateObject($this->_tbl,$this,$this->_tbl_key,false);        $this->setErr($this->_db->getErrorMsg());    }    function delete($ID){        $this->_db->setQuery("DELETE FROM $this->_tbl WHERE $this->_tbl_key='$ID'");        $this->_db->query();    }    function insertid(){        return $this->_db->insertid();    }    function getAffectedRows()    {        return $this->_db->getAffectedRows();    }    function setErr($errMsg){        $this->_db->_err_msg.=$errMsg;    }    function getErr(){        return $this->_db->_err_msg;    }    function inputData($prefix='tbl_')    {    global $input,$SET;       foreach($input as $key=>$value)       {          if(substr($key,0,strlen($prefix))==$prefix)          {               $var=substr($key,strlen($prefix));               $this->$var=$value;          }       }    }    function inputUpload($upload,$prefix='file_')    {    global $input;       if($upload)       foreach($upload as $key=>$value)       {          if(strtolower(substr($key,0,strlen($prefix)))==$prefix)          {               $var=substr($key,strlen($prefix));               $this->$var=$value[name];               $this->setErr($value[err]);          }       }    }}?>

⌨️ 快捷键说明

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