当前位置: 首页 > 图文教程 > 网络编程 > PHP > 一个MYSQL操作类

PHP
基于mysql的论坛(3)
基于mysql的论坛(7)
生成sessionid和随机密码的例子
基于mysql的论坛(6)
基于mysql的论坛(5)
基于mysql的论坛(4)
基于mysql的论坛(1)
基于mysql的论坛(2)
模仿OSO的论坛(五)
PHP4在Windows2000下的安装
用PHP实现多级树型菜单
如何删除多级目录
构建简单的Webmail系统
用文本文件实现的动态实时发布新闻的程序
信用卡效验程序
简单的用PHP编写的导航条程序
将RTF格式的文件转成HTML并在网页中显示的代码
利用 window_onload 实现select默认选择
PHP4.04简明安装
非常好的目录导航文件代码

PHP 中的 一个MYSQL操作类


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 65 ::
收藏到网摘: n/a

复制代码 代码如下:

<?php
class DB{
var $host_addr = "localhost";
var $host_user = "root";
var $host_psw = "123";
var $db_name = "test";
var $link_id;
var $query_id;
var $numRow;
function DB(){
$this->link_id = @mysql_connect($this->host_addr,$this->host_user,$this->host_psw);
if($this->link_id){
@mysql_select_db($this->db_name,$this->link_id) or $this->halt("数据库连接失败!");
}else{
$this->halt("连接服务器失败!");
return false;
}
return $this->link_id;
}
function query($sql){
$this->query_id = @mysql_query($sql,$this->link_id);
if($this->query_id){
return $this->query_id;
}else{
$this->halt("SQL Error::");
return false;
}
}
function numRow(){
return $this->numRow = @mysql_num_rows($this->query_id);
}
function close(){
return @mysql_close($this->link_id);
}
function halt($msg){
echo "<font color=\"#FF0000\">".$msg."</font>";
}
}
?>