kk at shonline dot de
05-Aug-1998 11:09
Oracle Example
Prerequisites:
You need to know the values of
the following environment variables:
ORACLE_HOME
This is the
path to your Oracle installation directory. It is usually defined in the
UNIX login script of your oracle user and all Oracle client
users.
ORACLE_SID
This is the name of the database instance
you want to connect to. It is also defined in the UNIX environment of your
oracle user and all Oracle client users.
Find out the values of
these variables by loggin in as a user who can connect to the database in
question with sqlplus. Then type at your Unix shell
prompt:
prompt> echo
$ORACLE_HOME
/opt/oracle/oracle/8.0.3
prompt> echo
$ORACLE_SID
ORACLE
A simple PHP script using ora_*
functions
<?php
putenv("ORACLE_SID=ORACLE");
putenv("ORACLE_HOME=/opt/oracle/oracle/8.0.3");
$conn
= ora_login("scott", "tiger");
$curs =
ora_open($conn);
ora_commitoff($conn);
$query =
sprintf("select * from cat");
/* Long version
*/
/*
ora_parse($curs, $query);
ora_exec($curs);
ora_fetch($curs);
*/
/* Short Version */
ora_do($conn,
$query);
$ncols = ora_numcols($curs);
$nrows =
ora_numrows($curs);
printf("Result size is $ncols cols by $nrows
rows.
");
for ($i=0; $i<$ncols; $i++) {
printf("col[%s] = %s type[%d] = %s
",
$i,
ora_columnname($curs, $i),
$i, ora_columntype($curs, $i));
}
for ($j=0; $j<$nrows; $j++) {
for ($i=0;
$i<$ncols; $i++) {
$col = ora_getcolumn($curs, $i);
printf("val[%d, %d] = %s * ", $j, $i, ora_getcolumn($curs,
$i);
}
printf("
");
}
?>