Home > php教程 > php手册 > body text

PHP程序来连接SQLServer数据库的通用类

WBOY
Release: 2016-06-13 10:06:58
Original
1594 people have browsed it

很多朋友问我如何用php程序来连接SQL Server数据库的通用类,其实这个并不是很难的,要害是一点点仔细,一点点耐心,用激情去理解

class DB {
var $Host = "192.168.0.199"; // Hostname of our MySQL server
var $Database = "test"; // Logical database name on that server
var $User = "user"; // Database user
var $Password = "password"; // Database user's password

var $Link_ID = 0; // Result of mssql_connect()
var $Query_ID = 0; // Result of most recent mssql_query()
var $Row = 0; // Current row number
var $Errno = 0; // Error state of query
var $Error = "";

var $AffNum=0;

/**************************************
*打印错误方法:显示页面处理的错误信息。
****************************************/
function Halt($msg) {
printf("Database error: %s
n", $msg);
printf("mssql Error: %s (%s)
n",
$this->Errno,
$this->Error);
die("Session halted.");
}

/**************************************
*连接数据库,并且选择默认的数据库
**************************************/
function Connect() {
if ( 0 == $this->Link_ID ) {
$this->Link_ID=mssql_connect($this->Host,$this->User,$this->Password) or die("Couldn't connect to SQL Server on

$servername");
Database,$this->Link_ID">$db=@mssql_select_db($this->Database,$this->Link_ID);
if (!$this->Link_ID) {
$this->Halt("Link-ID == false, mssql_connect failed");
}
}
}

/****************************************
*关闭数据库,假如数据库连接已经打开则关闭它
*请在调用Connect()并处理后使用Close()
****************************************/
function Close() {
if (0 != $this->Link_ID){
mssql_close();
}
}

/*************************************************
*输入sql语句,有select,update,insert,delete

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template