Cara menggunakan php oracle connection example

$c1 = oci_connect("hr", "welcome", 'localhost/XE');
$c2 = oci_connect("hr", "welcome", 'localhost/XE');

// Both $c1 and $c2 show the same PHP resource id meaning they use the
// same underlying database connection
echo "c1 is $c1
\n";
echo "c2 is $c2
\n";

function create_table($conn)
{
$stmt = oci_parse($conn, "create table hallo (test varchar2(64))");
oci_execute($stmt);
echo "Created table
\n";
}

function drop_table($conn)
{
$stmt = oci_parse($conn, "drop table hallo");
oci_execute($stmt);
echo "Dropped table
\n";
}

function insert_data($connname, $conn)
{
$stmt = oci_parse($conn, "insert into hallo
values(to_char(sysdate,'DD-MON-YY HH24:MI:SS'))");
oci_execute($stmt, OCI_DEFAULT);
echo "$connname inserted row without committing
\n";
}

function rollback($connname, $conn)
{
oci_rollback($conn);
echo "$connname rollback
\n";
}

function select_data($connname, $conn)
{
$stmt = oci_parse($conn, "select * from hallo");
oci_execute($stmt, OCI_DEFAULT);
echo "$connname ----selecting
\n";
while (oci_fetch($stmt)) {
echo " " . oci_result($stmt, "TEST") . "
\n";
}
echo "$connname ----done
\n";
}

create_table($c1);

insert_data('c1', $c1); // Insert a row using c1
sleep(2); // sleep to show a different timestamp for the 2nd row
insert_data('c2', $c2); // Insert a row using c2

select_data('c1', $c1); // Results of both inserts are returned
select_data('c2', $c2); // Results of both inserts are returned

// Both $c1 and $c2 show the same PHP resource id meaning they use the
// same underlying database connection
echo "c1 is $c1
\n";
echo "c2 is $c2
\n";
0

// Both $c1 and $c2 show the same PHP resource id meaning they use the
// same underlying database connection
echo "c1 is $c1
\n";
echo "c2 is $c2
\n";
1

// Both $c1 and $c2 show the same PHP resource id meaning they use the
// same underlying database connection
echo "c1 is $c1
\n";
echo "c2 is $c2
\n";
2

// Both $c1 and $c2 show the same PHP resource id meaning they use the
// same underlying database connection
echo "c1 is $c1
\n";
echo "c2 is $c2
\n";
3

// Both $c1 and $c2 show the same PHP resource id meaning they use the
// same underlying database connection
echo "c1 is $c1
\n";
echo "c2 is $c2
\n";
4

// Both $c1 and $c2 show the same PHP resource id meaning they use the
// same underlying database connection
echo "c1 is $c1
\n";
echo "c2 is $c2
\n";
5

saya ingin membuat koneksi dari php ke database oracle.. saya menggunakan OS win7 64bit, PHP 5.4.12, WAMP 2.4(64bit), oracle 11g.. di oracle 11, saya buka file tnsnames.oRA dan menuliskan:
 db =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.xxx)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = xxxx.xxxxx.net)
    )
  ) 
ket : x = disensor hehe Saya telah mengkonfigurasi pengaturan wamp (php.ini) dengan menghapus titik koma (;) ekstensi = php_oci8_11g.dll, Saya ingin membuat koneksi ke database oracle dengan menggunakan php. Saya mencoba dan masih eror .. apakah ada yang salah? koneksi.php:
  
Saya menjalankannya localhost dan hasilnya terlihat seperti ini:
Cara menggunakan php oracle connection example
Apakah ada yang salah ? Saya baru pertama kali menghubungkan oracle, saya sangat berterima kasih jika Anda bersedia membantu.

Pada kesempatan kali ini saya akan berbagi tentang koneksi php(XAMPP 1.7.7) ke oracle(Oracle11g). Hal yang harus diperhatikan sebelum kita membuat koneksi php ke oracle yaitu mengubah Configuration Setting php. File yang diubah yaitu php.ini yang berada di $XAMPP_HOME\php\.

Cara menggunakan php oracle connection example
Buka file tersebut dengan notepad ataupun notepad++, cari beberapa code yang terdapat kata oci lalu hilangkan tanda titik komanya(;).

Contoh:

;extension=php_oci8.dll ubah menjadi extension=php_oci8.dll

Begitupun dengan beberapa code di bawah ini:

[OCI 8]

oci8.privileged_connect = Off
oci8.max_persistent = -1
oci8.persistent_timeout = -1
oci8.ping_interval = 60
oci8.events = Off
oci8.statement_cache_size = 20
oci8.default_prefetch = 100
oci8.old_oci_close_semantics = Off

Setelah mengubah konfigurasi sertting barulah kita mulai koding.

Buatlah file koneksi.php

<?php
//membangun koneksi
$username="belajar";
$password="belajar";
$database="localhost/orcl";

$koneksi=oci_connect($username,$password,$database);

if($koneksi){
echo "Koneksi berhasil";
}else{
$err=oci_error();
echo "Gagal tersambung ke ORACLE". $err['text'];
}
?>

Simpan di $XAMPP_HOME/htdocs/oracle

Cara menggunakan php oracle connection example

Buka xampp-control lalu aktifkan Apache dan Mysqlnya.
Cara menggunakan php oracle connection example
Pastikan Apcahe dan Mysql nya running
Cara menggunakan php oracle connection example
Buka web browser dan ketikan http://www.localhost:8013/oracle/koneksi.php(port URL sesuaikan dengan settingan xamppnya)

Cara menggunakan php oracle connection example

koneksi php ke oracle berhasil

Kesalahan dalam penulisan username, password dan database merupakan penyebab gagalnya koneksi php ke oracle