/*取得结果数据*/
public function mysql_result_li() {
return mysql_result($str);
}
/*取得记录集,获取数组-索引和关联,使用$row['content'] */
public function fetch_array() {
return mysql_fetch_array($this->result);
}
// public function fetch_array($query) {
// return mysql_fetch_array($query);
// }
//获取关联数组,使用$row['字段名']
public function fetch_assoc() {
return mysql_fetch_assoc($this->result);
}
//获取数字索引数组,使用$row[0],$row[1],$row[2]
public function fetch_row() {
return mysql_fetch_row($this->result);
}
//获取对象数组,使用$row->content
public function fetch_Object() {
return mysql_fetch_object($this->result);
}
//简化查询select
public function findall($table) {
$this->query("SELECT * FROM $table");
}
//简化查询select
public function select($table, $columnName = "*", $condition = '', $debug = '') {
$condition = $condition ? ' Where ' . $condition : NULL;
if ($debug) {
echo "SELECT $columnName FROM $table $condition";
} else {
$this->query("SELECT $columnName FROM $table $condition");
}
}
//简化删除del
public function delete($table, $condition, $url = '') {
if ($this->query("DELETE FROM $table WHERE $condition")) {
if (!empty ($url))
$this->Get_admin_msg($url, '删除成功!');
}
}
//简化插入insert
public function insert($table, $columnName, $value, $url = '') {
if ($this->query("INSERT INTO $table ($columnName) VALUES ($value)")) {
if (!empty ($url))
$this->Get_admin_msg($url, '添加成功!');
}
}
//简化修改update
public function update($table, $mod_content, $condition, $url = '') {
//echo "UPDATE $table SET $mod_content WHERE $condition"; exit();
if ($this->query("UPDATE $table SET $mod_content WHERE $condition")) {
if (!empty ($url))
$this->Get_admin_msg($url);
}
}
/*取得上一步 INSERT 操作产生的 ID*/
public function insert_id() {
return mysql_insert_id();
}
//指向确定的一条数据记录
public function db_data_seek($id) {
if ($id > 0) {
$id = $id -1;
}
if (!@ mysql_data_seek($this->result, $id)) {
$this->show_error("SQL语句有误:", "指定的数据为空");
}
return $this->result;
}
// 根据select查询结果计算结果集条数
/* public function db_num_rows() {
if ($this->result == null) {
if ($this->show_error) {
$this->show_error("SQL语句错误", "暂时为空,没有任何内容!");
}
} else {
return mysql_num_rows($this->result);
}
}*/
public function db_num_rows($result){
if($result==null){
if ($this->show_error) {
$this->show_error("SQL语句错误", "暂时为空,没有任何内容!");
}
}else{
return mysql_num_rows($result);
}
}
// 根据insert,update,delete执行结果取得影响行数
public function db_affected_rows() {
return mysql_affected_rows();
}
//输出显示sql语句
public function show_error($message = "", $sql = "") {
if (!$sql) {
echo "" . $message . "";
echo " ";
} else {
echo "
";
echo " ";
}
//释放结果集
public function free() {
@ mysql_free_result($this->result);
}
//数据库选择
public function select_db($db_database) {
return mysql_select_db($db_database);
}
//查询字段数量
public function num_fields($table_name) {
//return mysql_num_fields($this->result);
$this->query("select * from $table_name");
echo " ";
echo "字段数:" . $total = mysql_num_fields($this->result);
echo "
//析构函数,自动关闭数据库,垃圾回收机制
public function __destruct() {
if (!empty ($this->result)) {
$this->free();
}
mysql_close($this->conn);
} //function __destruct();