Common php program to connect to SQLServer database

Source: Internet
Author: User
Many of my friends asked me how to use a php program to connect to a common class of SQL Server database. this is not very difficult. The key point is to be careful, patient, and knowledgeable? ClassDB {var $ Host = "192.168.0.199"; // HostnameofourMyS many friends asked me how to use a php program to connect to a common class of the SQL Server database. this is really not difficult, the key point is to be careful, be patient, and be considerate.
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 ('cooldn' 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 ');
}
}
}

/*************************************** *
* Closed the database. if the database connection has been opened, it will be closed.
* Apply Close () after Connect () is called and processed ()
****************************************/
Function Close (){
If (0! = $ This-> Link_ID ){
Mssql_close ();
}
}

/*************************************** **********
* Input SQL statements, including select, update, insert, and delete
* This method can also be used to include stored procedures.
**************************************** *********/
Function Query ($ Query_String ){
$ This-> Connect ();

$ This-> Query_ID = mssql_query ($ Query_String );
$ This-> Row = 0;

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.