Two Methods for connecting to sqlserver2000 in php5.3 (com and ODBC)

Source: Internet
Author: User
Tags odbc connection

1. Com link, ADODB. Connection

Copy codeThe Code is as follows:
$ Conn = new Com ("ADODB. Connection"); // instantiate a Connection object
$ Connstr = "provider = sqloledb; datasource =.; uid = sa; pwd = 123456; database = jnold ;";
$ Conn-> Open ($ connstr );
$ Rs = new Com ("ADODB. Recordset"); // instantiate a Recordcount object

$ Rs-> Open ('select * from News where bigclassid = 59 And LeadPostil is null', $ conn, 1, 1 );
$ Count = $ rs-> RecordCount;
Echo "A total of {$ count} records <br/> ";
For ($ I = 0; $ I <$ count; $ I ++ ){

$ Arr_result [$ I] ['title'] = addslashes ($ rs-> Fields ('title')-> Value); // Title
$ Arr_result [$ I] ['color'] = addslashes ($ rs-> Fields ('titlecolor')-> Value? $ Rs-> Fields ('titlecolor')-> Value: "); // Title color
$ Arr_result [$ I] ['wenhao'] = addslashes ($ rs-> Fields ('othertext')-> Value); // Document No.

}


2. ODBC connection mssql

Copy codeThe Code is as follows:
$ Dbhost = ";
$ Dbuser = "; // your mssql User Name
$ Dbpass = "; // your mssql Password
$ Dbname = "; // your mssql database name

$ Connect = odbc_connect ("Driver = {SQL Server}; Server = $ dbhost; Database = $ dbname", "$ dbuser", "$ dbpass ");
$ SQL = "select * from content ";
$ Exec = odbc_exec ($ connect, $ SQL );
While ($ row = (odbc_fetch_array ($ exec )))
{
$ Row ['id'] //? Field Value
...
}

Related Article

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.