connecting to an Oracle database from a php script via a web serv er.

From: MacDonell, Dennis (DennisMacDonell@auslig.gov.au)
Date: Mon Apr 22 2002 - 01:57:41 EDT


Hi,

I have setup php+mysql+oracle+apache on a Tru64 v5.1A installation with
oracle 8.1.7. The following sources were used -
autoconf-2.52
flex-2.5.4
php-4.1.2
automake-1.5
make-3.79.1
apache_1.3.23
bison-1.34
mysql-3.23.49.OSF1

I can run phpinfo(), and I have run ldd -r on httpd and checked that it has
a couple of oci8 library entries, but I can't get the following script to
work (adapted from the online manual)
***********************
<html>
<body BGCOLOR="#FFFFFF">

<?php
  putenv("LD_LIBRARY_PATH=/oracle_home/lib");
  putenv("ORACLE_HOME=/oracle_home");
  putenv("ORACLE_SID=ARC");

  /* OCIDefineByPos example thies@thieso.net (980219) */
  $db = "lando";

  $conn = OCILogon("test","oratest", $db);

  $stmt = OCIParse($conn,"select city, country from location");

  /* the define MUST be done BEFORE OCIexecute! */

  OCIDefinebyname($stmt,"CITY",$city);
  OCIDefinebyname($stmt,"COUNTRY",$country);

  OCIExecute($stmt);

  while (OCIFetch($stmt)) {
      echo "city:".$city."\n";
      echo "country:".$country."\n";
  }

  OCIFreestatement($stmt);
  OCILogoff($conn);
?>

</body>
</html>
**********************
What I get is the following
**********************
Warning: _oci_open_server: ORA-12154: TNS:could not resolve service name in
/www/Oracle/oracleoci.php on line 24

Warning: Supplied argument is not a valid OCI8-Connection resource in
/www/Oracle/oracleoci.php on line 26

Warning: Supplied argument is not a valid OCI8-Statement resource in
/www/Oracle/oracleoci.php on line 30

Warning: Supplied argument is not a valid OCI8-Statement resource in
/www/Oracle/oracleoci.php on line 31

Warning: Supplied argument is not a valid OCI8-Statement resource in
/www/Oracle/oracleoci.php on line 33
Warning: Supplied argument is not a valid OCI8-Statement resource in
/www/Oracle/oracleoci.php on line 36
*****************
The line numbers may not align because I have deleted a few lines from what
is shown of the script. I stopped the listener and created a file called
/oracle_home/admin/tnsnames.ora which contained the following
*****************
lando = (DESCRIPTION=
          (ADDRESS=
            (PROTOCOL=TCP)
            (HOST=lando)
            (PORT=1521))
        (CONNECT DATA=
            (SID=ARC)))
******************
and then restarted the listener, but alas that did not make any difference.
I was wondering if a knowledgeable person could shed some light on what is
missing.
Dennis

######################################
Dennis Macdonell
Systems Administrator
National Mapping Division, Geoscience Australia
mail: PO Box 2, Belconnen, ACT 2617
email: mcdonell@auslig.gov.au
ph: 61 2 6201 4326
fax: 61 2 6201 4377
######################################



This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 10:48:38 EDT