PHP Database ODBC

PHP Database ODBC

  
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:

  1. Open the Administrative Tools icon in your Control Panel. Buka icon Administrative Tools dalam Control Panel.
  2. Double-click on the Data Sources (ODBC) icon inside. Double-klik pada Sumber Data) ikon dalam ODBC (.
  3. Choose the System DSN tab. Pilih tab System DSN.
  4. Click on Add in the System DSN tab. Klik Tambah di tab System DSN.
  5. Select the Microsoft Access Driver . Pilih Microsoft Access Driver. Click Finish. Klik Finish.
  6. In the next screen, click Select to locate the database. Pada layar berikutnya, klik Pilih untuk mencari database.
  7. Give the database a Data Source Name (DSN) . Berikan database Data Source Name (DSN).
  8. Click OK . Klik OK.
Note that this configuration has to be done on the computer where your web site is located. Perhatikan bahwa konfigurasi ini harus dilakukan pada komputer mana situs web Anda berada. If you are running Internet Information Server (IIS) on your own computer, the instructions above will work, but if your web site is located on a remote server, you have to have physical access to that server, or ask your web host to to set up a DSN for you to use. Jika Anda menjalankan Internet Information Server (IIS) pada komputer Anda sendiri, petunjuk di atas akan bekerja, tetapi jika situs web Anda berada di server jauh, Anda harus memiliki akses fisik ke server itu, atau meminta tuan rumah web Anda untuk untuk membuat DSN untuk Anda gunakan.

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);
The code line below returns the value of a field called "CompanyName":
$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 "


CompanynameContactname
$compname$conname
";
?>

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