السلام عليكم

اليكم طريقة ربط قواعد البيانات اوراكل مع لغة php


خطوات التركيب

اتبع هذه الخطوات في اعدادات PHP لربط لقواعد بيانات أوراكل :

تحرير ملف php.ini وحرر السطرين التاليين :


كود:

كود:
   ;extension = php_oci8.dll 
;extension = php_oracle.dll




otherwise, compile PHP with the following options:


--
كود:
with-oracle=/path/to/oracle/home/dir 
--with-oci8=/path/to/oracle/home/dir

Ensure that your "extension_dir" parameter (in php.ini) points to the location where the above extension files reside.
Write a small program to test connectivity - see the next question


كود:

كود:
   <?php 
 if ($c=OCILogon("user", "pass", "orcl")) { 
   echo "تم الاتصال بقواعد بيانات اوراكل"; 
   OCILogoff($c); 
 } else { 
   $err = OCIError(); 
   echo "هناك خطأ لم يتم الربط "; 
 } 
 
////  الاصلي  
 
if ($c=OCILogon("scott", "tiger", "orcl")) { 
   echo "Successfully connected to Oracle.n"; 
   OCILogoff($c); 
 } else { 
   $err = OCIError(); 
   echo "Oracle Connect Error " . $err[text]; 
 } 
 
 ?>

Using the ORA Extension Module -


كود:

كود:
   <?php 
 if ($c=ora_logon("scott@orcl","tiger")) { 
   echo "Successfully connected to Oracle.n"; 
   ora_commitoff($c); 
   ora_logoff($c); 
 } else { 
   echo "Oracle Connect Error " . ora_error(); 
 } 
 ?>
طبعا من عمل مع قواعد بيانات اوراكل يعرف المستخدم scott


مثال عام لعمل جدول وتحديث البيانات


كود:

كود:
   <?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); 
 ?>