오래전 이야기/Open Tools

php+oracle 접속확인 스크립트

리눅스 엔지니어였던 2008. 9. 15. 17:54

How does one connect to Oracle?

Using the OCI Extension Module -
<?php
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();
}
?>
NOTE: You might want to set your Oracle environment from within PHP before connecting, look at this example:
<?php
  PutEnv("ORACLE_SID=ORCL");
  PutEnv("ORACLE_HOME=/app/oracle/product/9.2.0");
  PutEnv("TNS_ADMIN=/var/opt/oracle");
...

Please note that PHP will share/re-use connections if the same userid/password combination is used (more than once) on a particular "page" or httpd server session. One can use the OCINLogon() function to ensure one gets a new session. Use the OCIPLogon() function to make persistent connections.


==========================================


<출처: http://www.orafaq.com/faqphp.htm >