TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG:5212] PHP3 and oracle
Here are some:
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>");
}
?>
kk@shonline.de
05-Aug-1998 08:08
Suppose your ORACLE_HOME
is /opt/oracle/oracle/8.0.3 and you build a
version of PHP3 with
Oracle support on Solaris like this:
./configure --with-oracle
\
--with-config-file-path=/opt/GNUphp3/lib \
--with-exec-dir=/opt/bin \
--enable-debug=yes
\
--enable-safe-mode=no \
--enable-url-fopen-wrapper=yes \
--enable-track-vars=yes \
--prefix=/opt/GNUphp3
then the resulting PHP
binary will be dynamically linked against libclntsh.so in
/opt/oracle/oracle/lib.
The build process as generated by configure will
include this directory
with an -L option, but not with an -R option (run-time
library search path). This
means that the resulting binary will not be able to
find libclntsh.so by
itself, but depends on an appropriate LD_LIBRARY_PATH
set within the web server
CGI environment - which usually is not there. To
fix this, grab the
Makefile generated by configure and duplicate the
-L/opt/oracle/oracle/8.0.3/lib option as an
-R/opt/oracle/oracle/8.0.3/lib
option (your -L and -R
strings will look slightly different depending on the
values for your oracle
version and ORACLE_HOME). The -R option will
compile in the corrent
search path for libclntsh and you won't have any
LD_LIBRARY_PATH pains any
more.
stevel@nettek-llc.com
22-Jan-1999 04:01
<?php
putenv(
"ORACLE_SID=sid1");
putenv(
"ORACLE_HOME=/u01/app/oracle/product/8.0.5");
$handle = ora_plogon(
"SCOTT@sid1", "TIGER") or die;
$cursor =
ora_open($handle);
ora_commitoff($handle);
$query = "SELECT * FROM
EMP";
ora_parse($cursor, $query)
or die;
ora_exec($cursor);
echo "<HTML><PRE>\n";
echo "$query\n\n";
$numcols = 0;
while(ora_fetch($cursor))
{
$numcols =
ora_numcols($cursor);
for ($column=0;
$column < $numcols; $column++) {
$data =
trim(ora_getcolumn($cursor, $column));
if($data == "")
$data = "NULL";
echo "$data\t";
}
echo "\n";
}
$numrows =
ora_numrows($cursor);
echo "\nROWS RETURNED:
$numrows\n";
echo "</PRE></HTML>\n";
ora_close($cursor);
?>
cord@ragesoft.com
12-Feb-1999 01:02
Using "@dbname" in
ora_logon/ora_plogon will force a SQL*Net connect,
even if the database is on
the local host. It's more efficient to use the
ORACLE_SID environment
variable.
>>> "Troy Johnson" <troy@minco.com> 04/09 10:01 AM >>>
http://www.php3.com/ has a bunch of links and docs and stuff
>>> Clay Fandre <cfandre@minn.net> 04/09 9:56 AM >>>
Is anyone using PHP3 and oracle. We have a few oracle databases that
I
would like to interface with. Currently we are using Cold Fusion but
it's too slow for me. I compiled the php3 module with oracle
support,
but I am a little unsure on how to connect to the database. Anyone
have
any examples?
Clay
---------------------------------------------------------------------
To unsubscribe, e-mail: tclug-list-unsubscribe@listserv.real-time.com
For additional commands, e-mail:
tclug-list-help@listserv.real-time.com
Try our website: http://tclug.real-time.com
---------------------------------------------------------------------
To unsubscribe, e-mail: tclug-list-unsubscribe@listserv.real-time.com
For additional commands, e-mail:
tclug-list-help@listserv.real-time.com
Try our website: http://tclug.real-time.com