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

PHP
PHP新手上路(十四)
PHP新手上路(十三)
PHP新手上路(十二)
PHP新手上路(十一)
其他功能
用PHP动态生成虚拟现实VRML网页
一个可以删除字符串中HTML标记的PHP函数
让你同时上传 1000 个文件 (一)
php生成WAP页面
html中select语句读取mysql表中内容
在IIS上安装PHP4.0正式版
在PWS上安装PHP4.0正式版
简单的页面缓冲技术
Apache, PHP在Windows 9x/NT下的安装与配置 (一)
PHP新手上路(七)
PHP新手上路(六)
PHP新手上路(五)
PHP新手上路(四)
PHP新手上路(三)
PHP新手上路(二)

PHP 中的 一个MYSQL操作类


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 56 ::
收藏到网摘: 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>";
}
}
?>