Quick Search:
 
 PHP Code: Oracle with PHP Jump to:  
Category: >> PHP Code >> Oracle with PHP  

<< lastnext >>

Snippet Name: Oracle with PHP

Description: This example demonstrates how data can be SELECTed and manipulated via INSERT, UPDATE and DELETE statements using PHP and an Oracle database.

Comment: (none)

Language:
Highlight Mode: PHP
Last Modified: February 27th, 2009

<?PHP
 
$c=OCILogon("scott", "tiger", "orcl");
IF ( ! $c ) {
 ECHO "Unable to connect: " . VAR_DUMP( OCIError() );
 DIE();
}
 
// Drop old table...
$s = OCIParse($c, "drop table tab1");
OCIExecute($s, OCI_DEFAULT);
 
// Create new table...
$s = OCIParse($c, "create table tab1 (col1 number, col2 varchar2(30))");
OCIExecute($s, OCI_DEFAULT);
 
// Insert data into table...
$s = OCIParse($c, "insert into tab1 values (1, 'Frank')");
OCIExecute($s, OCI_DEFAULT);
 
// Insert data using bind variables...
$var1 = 2;
$var2 = "Scott";
$s = OCIParse($c, "insert into tab1 values (:bind1, :bind2)");
OCIBindByName($s, ":bind1", $var1);
OCIBindByName($s, ":bind2", $var2);
OCIExecute($s, OCI_DEFAULT);
 
// Select Data...
$s = OCIParse($c, "select * from tab1");
OCIExecute($s, OCI_DEFAULT);
WHILE (OCIFetch($s)) {
 ECHO "COL1=" . ociresult($s, "COL1") .
    ", COL2=" . ociresult($s, "COL2") . "n";
}
 
// Commit to save changes...
OCICommit($c);
 
// Logoff from Oracle...
OCILogoff($c);
 
?>
 


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org