Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create ODBC in php

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how to create ODBC in php". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

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.

This is the way to create an ODBC connection to the MS Access database:

Open the administrative tools icon in the 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 finish.

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

Give the database a data source name (DSN).

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 above instructions will take effect, but if your website 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 takes four parameters: the data source name, user name, password, and optional pointer type.

The odbc_exec () function is used to execute the SQL statement.

Example

The following example creates a connection to the DSN named northwind without a user name and password. Then create and execute a SQL statement:

$conn=odbc_connect ('northwind','',''); $sql= "SELECT * FROM customers"; $rs=odbc_exec ($conn,$sql); retrieve record

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 it returns false.

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

Odbc_fetch_row ($rs) retrieves fields from the record

The odbc_result () function is used to read fields from a record. The function takes two parameters: the ODBC result identifier and the field number or name.

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

$compname=odbc_result ($rs,1)

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

$compname=odbc_result ($rs, "CompanyName"); close the ODBC connection

The odbc_close () function closes the ODBC connection.

Odbc_close ($conn); that's all for "how to create ODBC in php". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report