note 74 modified in ref.oracle by irchtml
| From: | irchtml@php.net | Date: | Tue, 17 Feb 2004 14:35:10 +0000 |
| Subject: | note 74 modified in ref.oracle by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65305@lists.php.net to get a copy of this message | ||
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.<br>");
for ($i=0; $i<$ncols; $i++) {
printf("col[%s] = %s type[%d] = %s<br>",
$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("<br>");
}
?>
--was--
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.<br>");
for ($i=0; $i<$ncols; $i++) {
printf("col[%s] = %s type[%d] = %s<br>",
$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("<br>");
}
?>
http://www.php.net/manual/en/ref.oracle.php