php实现比较全的数据库操作类
网络编程 2021-07-05 09:09www.168986.cn编程入门
这篇文章主要介绍了php实现比较全的数据库操作类,可实现基本的数据库连接、执行SQL语句及错误提示等相关技巧,需要的朋友可以参考下
本文实例讲述了php实现比较全的数据库操作类。分享给大家供大家参考。具体如下:
<?php class database { private $hostname; private $user; private $pass; private $dbname; private $linkflag; private $charset; function __construct() { $this->hostname="localhost"; $this->user="root"; $this->pass="111"; $this->dbname=""; $this->charset="utf8"; //gb2312 GBK utf8 $this->linkflag=mysql_connect($this->hostname,$this->user,$this->pass); mysql_select_db($this->dbname,$this->linkflag) or die($this->error()); mysql_query("set names ".$this->charset); } function __set($property_name,$value) { return $this->$property_name=$value; } function __get($property_name) { if(isset($this->$property_name)) { return $this->$property_name; } else return null; } function __call($function_name, $args) { echo "<br><font color=#ff0000>你所调用的方法 $function_name 不存在</font><br>\n"; } function query($sql) { $res=mysql_query($sql) or die($this->error()); return $res; } function fetch_array($res) { return mysql_fetch_array($res); } function fetch_object($res) { return mysql_fetch_object($res); } function fetch_obj_arr($sql) { $obj_arr=array(); $res=$this->query($sql); while($row=mysql_fetch_object($res)) { $obj_arr[]=$row; } return $obj_arr; } function error() { if($this->linkflag) { return mysql_error($this->linkflag); } else return mysql_error(); } function errno() { if($this->linkflag) { return mysql_errno($this->linkflag); } else return mysql_errno(); } function affected_rows() { return mysql_affected_rows($this->linkflag); } function num_rows($sql) { $res=$this->execute($sql); return mysql_num_rows($res); } function num_fields($res) { return mysql_num_fields($res); } function insert_id() { $previous_id=mysql_insert_id($this->linkflag); return $previous_id; } function result($res,$row,$field=null) { if($field===null) { $res=mysql_result($res,$row); } else $res=mysql_result($res,$row,$field); return $res; } function version() { return mysql_get_server_info($this->linkflag); } function data_seek($res,$rowNum) { return mysql_data_seek($res,$rowNum); } function __destruct() { //mysql_close($this->linkflag); } } ?>
希望本文所述对大家的php程序设计有所帮助。
上一篇:php实现的简单检验登陆类
下一篇:php文件操作相关类实例
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程