Mysql.class.php 下载
复制代码 代码如下:
<?php
class Mysql {
private $db_host; //主机地址
private $db_user; //用户名
private $db_pass; //连接密码
private $db_name; //名称
private $db_charset; //编码
private $conn;
public $debug=false;//调试开关,默认关闭
private $query_id; //用于判断sql语句是否执行成功
private $result; //结果集
private $num_rows; //结果集中行的数目,仅对select有效
private $insert_id; //上一步 INSERT 操作产生的 ID
// 构造/析构函数
function __construct ($db_host,$db_user,$db_pass,$db_name,$db_charset,$conn) {
$this->db_host = $db_host ;
$this->db_user = $db_user ;
$this->db_pass = $db_pass ;
$this->db_name = $db_name ;
$this->db_charset = $db_charset ;
$this->conn = $conn ;
$this->connect();
}
function __destruct () {
@mysql_close($this->conn);
}
// 连接/选择数据库
public function connect () {
if ($this->conn == 'pconn') {
@$this->conn = mysql_pconnect($this->db_host,$this->db_user,$this->db_pass);
} else {
@$this->conn = mysql_connect($this->db_host,$this->db_user,$this->db_pass);
}
if (!$this->conn) {
$this->show_error('数据库-连接失败:用户名或密码错误!');
}
if (!@mysql_select_db($this->db_name,$this->conn)) {
$this->show_error("数据库-选择失败:数据库 $this->db_name 不可用");
}
mysql_query("SET NAMES $this->db_charset");
return $this->conn;
}
// query方法
public function query ($sql) {
if ($this->query_id) $this->free_result();
$this->query_id = @mysql_query($sql,$this->conn);
if (!$this->query_id) $this->show_error("SQL语句 <b>\"$sql\"</b> 执行时遇到错误");
return $this->query_id;
}
// 显示详细错误信息
public function show_error ($msg) {
if($this->debug){
$errinfo = mysql_error();
echo "错误:$msg <br/> 返回:$errinfo<p>";
}else{
echo '<p>出现错误!<p>';
}
}
// 获得query执行成功与否的信息
public function get_query_info($info){
if ($this->query_id) {
echo $info;
}
}
// 查询所有
public function findall ($table_name) {
$this->query("select * from $table_name");
}
// mysql_fetch_array
public function fetch_array () {
if ($this->query_id) {
$this->result = mysql_fetch_array($this->query_id);
return $this->result;
}
}
// ......
public function fetch_assoc () {
if ($this->query_id) {
$this->result = mysql_fetch_assoc($this->query_id);
return $this->result;
}
}
public function fetch_row () {
if ($this->query_id) {
$this->result = mysql_fetch_row($this->query_id);
return $this->result;
}
}
public function fetch_object () {
if ($this->query_id) {
$this->result = mysql_fetch_object($this->query_id);
return $this->result;
}
}
// 获取 num_rows
public function num_rows () {
if ($this->query_id) {
$this->num_rows = mysql_num_rows($this->query_id);
return $this->num_rows;
}
}
// 获取 insert_id
public function insert_id () {
return $this->insert_id = mysql_insert_id();
}
// 显示共有多少张表
public function show_tables () {
$this->query("show tables");
if ($this->query_id) {
echo "数据库 $this->db_name 共有 ".$this->num_rows($this->query_id)." 张表<br/>";
$i = 1;
while ($row = $this->fetch_array($this->query_id)){
echo "$i -- $row[0]<br/>";
$i ++;
}
}
}
// 显示共有多少个数据库
public function show_dbs(){
$this->query("show databases");
if ($this->query_id) {
echo "共有数据库 ".$this->num_rows($this->query_id)." 个<br/>";
$i = 1;
while ($this->row = $this->fetch_array($this->query_id)){
echo "$i -- ".$this->row[Database]."<br />";
$i ++;
}
}
}
// 删除数据库:返回删除结果
public function drop_db ($db_name='') {
if ($db_name == '') {
$db_name = $this->db_name;//默认删除当前数据库
$this->query("DROP DATABASE $db_name");
}else {
$this->query("DROP DATABASE $db_name");
}
if ($this->query_id) {
return "数据库 $db_name 删除成功";
}else {
$this->show_error("数据库 $db_name 删除失败");
}
}
// 删除数据表:返回删除结果
public function drop_table ($table_name) {
$this->query("DROP TABLE $table_name");
if ($this->query_id) {
return "数据表 $table_name 删除成功";
}else {
$this->show_error("数据表 $table_name 删除失败");
}
}
// 创建数据库
public function create_db ($db_name) {
$this->query("CREATE DATABASE $db_name");
if($this->query_id){
return "数据库 $db_name 创建成功";
}else {
$this->show_error("数据库 $db_name 创建失败");
}
}
// 获取数据库版本
public function get_info(){
echo mysql_get_server_info();
}
// 释放内存
public function free_result () {
if ( @mysql_free_result($this->query_id) )
unset ($this->result);
$this->query_id = 0;
}
} // End class
?>
相关推荐:
“赞片CMS”-让你的*站点管理更高效、便捷,日照seo平台
seo需要什么人员,seo需要什么技能 ,画大学ai
seo需要会什么,seo要会些什么 ,ai313414919
目前最火的AI软件有哪些?深度解析必备工具
seo涉及什么内容,seo主要包括 ,法医使用ai
目前AI软件有哪些?智能新时代的必备工具
SEO做好,企业网站流量翻倍的关键,seo白帽技术有哪些
ChatGPT为什么打不开?背后原因与解决方案,慧ai写作
SEO优化的话题:助力企业成功的关键,夏杰ai智能管家
什么是SEO优化方案,seo的优化方案 ,ai emorobot
ChatGPT故障:科技背后的秘密与应对策略,华为什么手机带ai功能
什么是seo网络推广,seo网络推广技术 ,ai写真官方
AI公众号文章生成,轻松打造爆款内容
seo该从什么开始,seo是什么时候开始的 ,ai写作免费英文怎么说
SEO立刻:快速提升网站排名,带你走在搜索引擎前沿,网站建设怎么推广好做
文章缩写AI:高效编辑的未来之光
SEO学费多少钱?揭秘SEO培训的投资价值与回报!,郴州网站推广多少钱一个
ChatGPT全球宕机:人工智能的崩塌与未来的挑战,中国ai和美国ai教父
seo适合什么行业,seo适合的行业 ,在ai如何矢量化
SEO获客的秘诀:如何通过搜索引擎优化提升客户获取能力,厦门seo搜索优化排名
SEO如何做?全方位解析提升网站排名的秘诀,AI翻译好处
ChatGPTCanvex打不开?详细分析及解决方法助你顺利使用,ai2.5d网格线去除
ChatGPT出现错误503?你需要知道的解决方案和应对策略,ai拉伸字效
ChatGPT:引领智能对话新潮流,助力未来科技,ai写作免费议论文
专业关键词助力SEO优化,让你的内容脱颖而出,东营响应式网站优化
文章去AI回归创作的本真之美
了解SEO:让你的网站在搜索引擎中脱颖而出的秘密武器,宝山区常见网站优化
seo需要学会什么编程,seo要会些什么 ,剪映怎样加ai
AI网页效果生成:开启网站设计的新纪元,ai画线祥云
怎样使用AI写文章:释放创作潜能,提升写作效率
为什么seo吸引人,为什么seo吸引人呢 ,ai路径查找器绘制树
二创AI:打破创意壁垒,引领未来内容创作新潮流,背影教案网站建设游戏
怎么用AI生成文章?全新写作方式的揭秘与应用指南
OpenAI推出的GPT-4Turbo大幅降低了AI应用成本,推动了AI技术的普及化,ai*版
GPT在智能聊天机器人中的作用:重塑沟通体验,开创智能未来,百万级ai
AI人工智能:开发与应用的必备软件推荐
seo需要什么器械,seo需要什么器械才能做 ,长续航ai纯电汽车
用AI写一篇文章,如何提升你的写作效率与创意
为什么做seo矩阵项目,为什么做seo矩阵项目不能做 ,怎么用ai写作
SEM做得好可以取代SEO吗?浅析两者的异同与未来趋势,王道ai
【SEO优化全攻略】提升网站流量的终极秘籍,带你轻松玩转搜索引擎优化!,金融网站推广维护
ChatGPT无法加载?检查您的网络设置并尝试重启ChatGPT,解决您的使用困扰!,ai光晕制作
AI提取文章重要内容:让信息抓取更高效、更精准,松鼠ai 教学
《*采集站:带你领略全球最全*资源的宝藏平台》,seo优化易下拉瞧瞧
AI免费生成文本,内容创作新篇章
什么是SEO金融,seo是做什么的 ,ai中转程序
SEO韩国:为您开启国际市场的增长之门,seo文章标题有哪些
seo要寻找什么资源,怎么找seo ,ai插画描边
ChatGPT启动时遇到问题?快速解决方案让你畅享智能对话体验,ai如何保存logo
文章续写AI:提升写作效率,创意无限