
ODBC adalah Application Programming Interface (API) yang memungkinkan Anda untuk terhubung ke sumber data (misalnya database MS Access).
Create an ODBC Connection Buat Koneksi ODBC
With an ODBC connection, you can connect to any database, on any computer in your network, as long as an ODBC connection is available. Dengan koneksi ODBC, Anda dapat terhubung ke database apapun, pada setiap komputer di jaringan anda, selama koneksi ODBC tersedia.Here is how to create an ODBC connection to a MS Access Database: Berikut adalah cara membuat koneksi ODBC ke MS Access Database:
- Open the Administrative Tools icon in your Control Panel. Buka icon Administrative Tools dalam Control Panel.
- Double-click on the Data Sources (ODBC) icon inside. Double-klik pada Sumber Data) ikon dalam ODBC (.
- Choose the System DSN tab. Pilih tab System DSN.
- Click on Add in the System DSN tab. Klik Tambah di tab System DSN.
- Select the Microsoft Access Driver . Pilih Microsoft Access Driver. Click Finish. Klik Finish.
- In the next screen, click Select to locate the database. Pada layar berikutnya, klik Pilih untuk mencari database.
- Give the database a Data Source Name (DSN) . Berikan database Data Source Name (DSN).
- Click OK . Klik OK.
Connecting to an ODBC Koneksi ke sebuah ODBC
The odbc_connect() function is used to connect to an ODBC data source. The odbc_connect () Fungsi ini digunakan untuk terhubung ke sumber data ODBC. The function takes four parameters: the data source name, username, password, and an optional cursor type. Fungsi ini mengambil empat parameter: nama data source, username, password, dan jenis kursor opsional.The odbc_exec() function is used to execute an SQL statement. The odbc_exec () Fungsi ini digunakan untuk menjalankan statemen SQL.
Example Contoh
The following example creates a connection to a DSN called northwind, with no username and no password. Contoh berikut membuat suatu koneksi ke DSN yang diberi nama northwind, tanpa username dan password. It then creates an SQL and executes it: Kemudian menciptakan SQL dan mengeksekusinya:| $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. This function returns true if it is able to return rows, otherwise false.The function takes two parameters: the ODBC result identifier and an optional row number:
| odbc_fetch_row($rs) |
Retrieving Fields from a Record
The odbc_result() function is used to read fields from a record. This function takes two parameters: the ODBC result identifier and a field number or name.The code line below returns the value of the first field from the record:
| $compname=odbc_result($rs,1); |
| $compname=odbc_result($rs,"CompanyName"); |
Closing an ODBC Connection
The odbc_close() function is used to close an ODBC connection.| odbc_close($conn); |
An ODBC Example
The following example shows how to first create a database connection, then a result-set, and then display the data in an HTML table.";
echo "";
echo "";
while (odbc_fetch_row($rs))
{
$compname=odbc_result($rs,"CompanyName");
$conname=odbc_result($rs,"ContactName");
echo "";
echo "";
}
odbc_close($conn);
echo "
| Companyname | Contactname |
|---|---|
| $compname | $conname |
?>


Bagaimana Dengan Artikel ini....Silahkan Berkomentar Jika ada Pertanyaan Dan Masukan ^_^