About the PHP database ODBC related content

Source: Internet
Author: User
Tags dsn odbc connection php database
PHP database ODBC is more important in PHP database, so this article will explain in detail the PHP database ODBC knowledge.

ODBC is an application programming interface (application programming Interface,api) that gives us the ability to connect to a data source (such as an MS Access database).

Create an ODBC connection

With an ODBC connection, you can connect to any database on any computer in your network, as long as the ODBC connection is available.

Here's how to create an ODBC connection that reaches the MS Access database:

Open the Administrative Tools icon in Control Panel.

Double-click the data Source (ODBC) icon in it.

Select the System DSN tab.

Click Add in the System DSN tab.

Select Microsoft Access Driver. Click Done.

In the next screen, click Select to locate the database.

Start a data source name (DSN) for the database.

Click OK.

Please note that this configuration must be done on the same computer as your website. If Internet Information Services (IIS) is running on your computer, the instructions above will take effect, but if your site is located on a remote server, you must have physical access to that server, or ask your host provider to establish a DSN for you.

Connect to ODBC

The Odbc_connect () function is used to connect to an ODBC data source. The function has four parameters: the data source name, the user name, the password, and the optional pointer type.

The Odbc_exec () function is used to execute SQL statements.

Instance

The following instance creates a connection to a DSN named Northwind with no user name and password. Then create and execute an SQL statement:

$conn =odbc_connect (' Northwind ', ', '); $sql = "SELECT * from Customers"; $rs =odbc_exec ($conn, $sql);

Retrieving records

The Odbc_fetch_row () function is used to return records from the result set. If the row can be returned, the function returns True, otherwise false is returned.

The function has two parameters: the ODBC result identifier and the optional line number:

Odbc_fetch_row ($RS)

Retrieving fields from records

The Odbc_result () function is used to read a field from a record. The function has two parameters: an ODBC result identifier and a field number or name.

The following line of code returns the value of the first field from a record:

$compname =odbc_result ($rs, 1);

The following line of code returns the value of the field named "CompanyName":

$compname =odbc_result ($rs, "CompanyName");

To close an ODBC connection

The Odbc_close () function is used to close an ODBC connection.

Odbc_close ($conn);

ODBC instance

The following example shows how to create a database connection first, create a result set, and then display the data in an HTML table.


This article explains in detail the PHP database ODBC related knowledge, more study material clear concern PHP Chinese network can watch.

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.