Home > Backend Development > PHP Tutorial > PHP program to connect to the common class of SQLServer database_PHP tutorial

PHP program to connect to the common class of SQLServer database_PHP tutorial

WBOY
Release: 2016-07-13 17:03:45
Original
1034 people have browsed it

Many friends asked me how to use php program to connect to the general class of SQL Server database. In fact, this is not difficult. The key is to be a little careful, a little patient, and understand with passion
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;

/**************************************
*Print error method: Display page processing error information.
****************************************/
function Halt($msg) {
printf("Database error: %s
n", $msg);
printf("mssql Error: %s (%s)
n",
$this->Errno,
$this->Error);
die("Session halted.");
}

/**************************************
*Connect to the database and select the default database
**************************************/
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");
}
}
}

/**************************************
*Close the database, if the database connection is already open, close it
*Please use Close()
after calling Connect() and processing ****************************************/
function Close() {
if (0 != $this->Link_ID){
mssql_close();
}
}

/******************************************************
*Enter sql statements, including select, update, insert, delete

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630926.htmlTechArticleMany friends asked me how to use PHP programs to connect to the general classes of SQL Server databases. In fact, this is not difficult. , the key is to be a little careful, a little patient, and understand with passion? cl...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template