Use php and MySql to connect to ODBC data

Source: Internet
Author: User
Use php and MySql to connect to ODBC data. read about using php and MySql to connect to ODBC data. ODBC refers to open data connection, which is a data driver dominated by Microsoft, it can be connected to other data and operated on data through the SQL language. of course, PHP also provides functions for ODBC data connection, PHP and ODBC connections are mainly implemented through several functions. "> <LINKhref ODBC refers to an open data connection, which is a data driver dominated by Microsoft and can be connected to other data, the SQL language is used to operate data. of course, PHP also provides functions for ODBC data connection,
Using PHP to connect to ODBC mainly involves several functions,
First, let's first understand several functions with ODBC interfaces:
Int odbc_connect (string dsn, string user, string password, int [cursor_type]); connected to ODBC database
Dsn, user, and password correspond to the content in ODBC, and cursor_type is the choice of the cursor type (you can check other documents, here I use its default value)
Int odbc_do (int connection_id, string query); it is a function used to execute the SQL language. connecton_id is the value returned by odbc_connecti. query is the SQL language statement we are most concerned about,
String odbc_result (int result_id, mixed field); it is a function for retrieving data, result_id is the return value of odbc_do execution, and field is the field index value.
Void odbc_close (int connection_id); closes data connections.
We first use these functions to connect to ODBC.
We assume that you can set dsn to yuange user and password in ODBC. of course, if you want to connect to SQL Server, you need user and password!
There is a counter table in yuange.

$ Conid = odbc_connect ("yuange ","","");
$ SQL = "select * from counter ";
$ Resid = odbc_do ($ conid, $ SQL );
While (odbc_fetch_row ($ resid )){
$ Serial = odbc_result ($ resid, 1 );
$ Riqi = odbc_result ($ resid, 2 );
If ($ serial % 2 ){
Echo $ serial. "". $ riqi ."
";
}
}
Odbc_close ($ conid );
?>
I installed PWS with php4.0 and mysql3.02 on Win98, which worked well.

[This article is copyrighted by the author and osuo. if you need to reprint it, please indicate the author and its source]


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.