$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
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\.
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
Buka xampp-control lalu aktifkan Apache dan Mysqlnya.
koneksi php ke oracle berhasil
Kesalahan dalam penulisan username, password dan database merupakan penyebab gagalnya koneksi php ke oracle