juan_tanga
asked on
how to connect to a remote oracle database using php
How do i connect to a remote oracle using php? I'm running php 4.0.6/apache on red hat linux. What do i need to install in order to access the remote oracle database?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Can i download the Oracle client libraries on their website?
i think you just have to include the php_oci8.dll and/or the php_oracle.dll in the php.ini depending on the interface you want to use (you can use two sets of functions to access the db: ora_xxx and oci_xxx). the dlls are in your php/extensions directory. you also have to fill in the correct extensions path at extension_dir = "", so the php.exe may find these dlls.
this version of php does support oracle, you just have to switch it on.
good luck.
this version of php does support oracle, you just have to switch it on.
good luck.
sorry
just recognized u r using linux
actualy it should be something simmilar
good luck again
just recognized u r using linux
actualy it should be something simmilar
good luck again
No you can't. Oracle doesn't provide the client libraries for download. You need to get a copy of Oracle for Linux. one of the trial versions that they have available for download may do the job.
ASKER
i downloaded the oracle8i enterprise for linux. Is it compatible to Oracle 8 (not i) enterprise edition? co'z thats our serving running on windows nt
Yes the client libraries should be backwards compatible.
You have to install a oracle client. Versions 8.1.6 or 8.1.7 for linux will fit your needs. As you wrote that you use linux I assume that you use apache/php combonation. To get the whole thin working you will have to export the oracle variables
Simply put theese line to your /etc/profile
ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/Or aHome1
ORA_NLS33=/opt/oracle/OraH ome1/ocomm on/nls/adm in/data
ORACLE_OWNER=oracle
NLS_LANG=AMERICAN_AMERICA. EE8ISO8859 P2
TNS_ADMIN=/opt/oracle/OraH ome1/netwo rk/admin
of course replace the paths to fit your installation. don't forget to export the variables. The next thing is you have to
set up your tnsnames.ora and sqlnet.ora located in TNS_ADMIN directory
here is a sample sqlnet.ora file
names.default_domain = WORLD
name.default_zone = WORLD
names.directory_path = (TNSNAMES, HOSTNAME)
and here is a sample tnsnames.ora entry
ORACLE_SID.WORLD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (COMMUNITY = tcp.world)(PROTOCOL = TCP)(Host = 12.2.33.12)(Port = 1521))
(ADDRESS = (COMMUNITY = tcp.world)(PROTOCOL = TCP)(Host = 12.2.33.12)(Port = 1526))
)
(CONNECT_DATA = (SID = ORACLE_SID)(SERVER=DEDICAT ED))
)
to test it try first the tnsping utility tnsping oracle_sid if it returns OK try sqlplus username/password@oracle_s id to log on to database. if you succeed yout oracle instalation works correctly.
And one common pitfall: you might get some trouble when starting the apache instance with apachectl script it does not read the enviroment variables. try to start it with the original httpd script. Another solution is to put the variables from /etc/profile to the starting script and also to the apache owners .bash_profile.
To make sure that everything is in place try to write a sample php script
<?
echo getenv("ORACLE_HOME");
echo getenv("TNS_ADMIN");
echo getenv("NLS_LANG");
?>
that's all hope it helps
Simply put theese line to your /etc/profile
ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/Or
ORA_NLS33=/opt/oracle/OraH
ORACLE_OWNER=oracle
NLS_LANG=AMERICAN_AMERICA.
TNS_ADMIN=/opt/oracle/OraH
of course replace the paths to fit your installation. don't forget to export the variables. The next thing is you have to
set up your tnsnames.ora and sqlnet.ora located in TNS_ADMIN directory
here is a sample sqlnet.ora file
names.default_domain = WORLD
name.default_zone = WORLD
names.directory_path = (TNSNAMES, HOSTNAME)
and here is a sample tnsnames.ora entry
ORACLE_SID.WORLD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (COMMUNITY = tcp.world)(PROTOCOL = TCP)(Host = 12.2.33.12)(Port = 1521))
(ADDRESS = (COMMUNITY = tcp.world)(PROTOCOL = TCP)(Host = 12.2.33.12)(Port = 1526))
)
(CONNECT_DATA = (SID = ORACLE_SID)(SERVER=DEDICAT
)
to test it try first the tnsping utility tnsping oracle_sid if it returns OK try sqlplus username/password@oracle_s
And one common pitfall: you might get some trouble when starting the apache instance with apachectl script it does not read the enviroment variables. try to start it with the original httpd script. Another solution is to put the variables from /etc/profile to the starting script and also to the apache owners .bash_profile.
To make sure that everything is in place try to write a sample php script
<?
echo getenv("ORACLE_HOME");
echo getenv("TNS_ADMIN");
echo getenv("NLS_LANG");
?>
that's all hope it helps
ASKER
thanks but I guess i don't need it anymore co'z i already connected using the username@host format in ora_logon()command in php.
ASKER