PHP program to connect to the SQLServer database common class _ PHP Tutorial

Source: Internet
Author: User
PHP program to connect to a common class of SQL Server database. Many of my friends asked me how to use a php program to connect to a common class of SQLServer database. In fact, this is not very difficult. The key point is to be careful, patient, and understanding with passion? Cl many friends asked me how to use a php program to connect to a common class of SQL Server database. In fact, this is not very difficult. The key point is to be careful, patient, and understanding 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: displays the error information processed on the page.
****************************************/
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 ");
}
}
}

/*************************************** *
* Shut down the database. if the database connection is already enabled, close it.
* Use Close () after Connect () is called and processed ()
****************************************/
Function Close (){
If (0! = $ This-> Link_ID ){
Mssql_close ();
}
}

/*************************************** **********
* The input SQL statements include select, update, insert, and delete.

In fact, this is not very difficult for the generic category of the Server database. The key point is to be careful, be patient, and understand it with passion? Cl...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.