在网上,有很多的,例如:
<?php
CLASS DB{
private $dbhost = 'localhost';
private $dbname = 'sp1168';
private $dbuser = 'sa';
private $dbpass = 'y1u2a3n6';
private $dblink = false;
private $errsql;public function __construct(){
   $this->dblink = @mssql_pconnect($this->dbhost,$this->dbuser,$this->dbpass) or die($this->halt());
   @mssql_select_db($this->dbname,$this->dblink);
}public function exec($sql){
    $this->errsql = $sql;
    $query = mssql_query($sql) or die($this->halt());
    return $query;
}public function fetch($query,$result_type = MSSQL_ASSOC){
   $row = mssql_fetch_array($query,$result_type);
   return $row;
}
public function affected_rows(){
   return mssql_rows_affected($this->dblink) or die ($this->halt());
}public function num_rows($query){
   return mssql_num_rows($query);
}public function free_result($query) {
    return @mssql_free_result($query) or die($this->halt());;
   }public function insert_id(){
   $query = $this->query("SELECT @@IDENTITY as last_insert_id");
   $row = $this->fetch($query);
   $this->free_result($query);
   return $row['last_insert_id'];
}public function seek($query,$offset){
   @mssql_data_seek($query,$offset) or die($this->halt());;
}public function halt(){
   $error = mssql_get_last_message();
   return 'MsSQL Error: '.$error."<br>".$this->errsql;
}public function get_one($sql){
   $query = $this->exec($sql);
   $row = $this->fetch($query);
   $this->free_result($query);
   return $row;
}
}
$dbh=new DB;
?>

解决方案 »

  1.   

    这个网页里面有一个很全面的,你看一下,这里很难复制那个类http://www.phpchina.com/bbs/viewthread.php?tid=15229
      

  2.   

    建议你用phpbb的类吧,支持流行的数据库,很容易使用的。
    www.phpbb.comA SQL database system, one of:MySQL 3.23 or above (MySQLi supported)
    PostgreSQL 7.3+
    SQLite 2.8.2+
    Firebird 2.0+
    MS SQL Server 2000 or above (directly or via ODBC)
    Oracle
      

  3.   

    用PDO比较好.不需要第三方类了.http://cn.php.net/manual/en/ref.pdo-dblib.php#86668