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

PHP
PHP 高手之路(三)
PHP 高手之路(二)
PHP 高手之路(一)
PHP4与PHP3中一个不兼容问题的解决方法
在Windows版的PHP中使用ADO
用PHP产生动态的影像图
最简单的PHP程序--记数器
动态新闻发布的实现及其技巧
php4的session功能评述(二)
php4的session功能评述(一)
php4的session功能评述(三)
一个用php3编写的简单计数器
福利彩票幸运号码自动生成器
杏林同学录(三)
用PHP来写记数器(详细介绍)
PHP的FTP学习(二)
杏林同学录(五)
我的论坛源代码(五)
PHP的FTP学习(三)
我的论坛源代码(四)

PHP 中的 一个MYSQL操作类


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