我正在尝试使用
PHP和Perl脚本设置CentOS 5.5 / 64位VM来访问远程Oracle数据库. (我没有使用Oracle的经验,之前只编写和管理过一些Postgresql和MysqL.)
我已经安装了以下Oracle Instant Client rpm:
oracle-instantclient11.2-basic-11.2.0.2.0.x86_64.rpm oracle-instantclient11.2-devel-11.2.0.2.0.x86_64.rpm oracle-instantclient11.2-sqlplus-11.2.0.2.0.x86_64.rpm
并将以下变量添加到我的.bash_profile:
export TNS_ADMIN=/etc export ORACLE_HOME=/usr/lib/oracle/11.2 export LD_LIBRARY_PATH=$ORACLE_HOME/client64/lib PATH=$PATH:$HOME/bin:/sbin:$ORACLE_HOME/client64/bin
在文件/etc/tnsnames.ora中,我编写了从运行Oracle数据库的远程站点的同事那里收到的信息:
some_string = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = my_address)(PORT = my_port)) ) (CONNECT_DATA = (SERVICE_NAME = PDTT) ) )
好的部分是我现在可以通过运行从CLI连接
sqlplus 'my_user/my_password@//my_address:my_port/PDTT'
然后通过发出可以看到一些表格:
select table_name from user_tables;
而且我也成功运行了sudo pecl install oci8,添加了文件/etc/PHP.d/oci8.ini,其中包含:
extension=oci8.so
现在我的问题和问题请:
1)如何设置ORACLE_SID变量以及如何在设置后调用sqlplus?可以/我应该使用PHP和Perl脚本中的ORACLE_SID吗?
2)我运行sudo -E perl -MCPAN -e shell,它在安装其他Perl模块时运行良好,但对于“install DBD :: Oracle”,它失败了:
CPAN.pm: Going to build T/TI/TIMB/DBD-Oracle-1.26.tar.gz Using DBI 1.52 (for perl 5.008008 on x86_64-linux-thread-multi) installed in /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBI/ Configuring DBD::Oracle for perl 5.008008 on linux (x86_64-linux-thread-multi) Remember to actually *READ* the README file! Especially if you have any problems. The ORACLE_HOME environment variable value (/usr/lib/oracle/11.2) is not valid. It must be set to hold the path to an Oracle installation directory on this machine (or a machine with a compatible architecture). For an Instant Client install,the directory should include an sdk subdirectory. See the appropriate README file for your OS for more information. ABORTED! Running make test Make had some problems,maybe interrupted? Won't test Running make install Make had some problems,maybe interrupted? Won't install
它提到上面的“sdk”目录,但转速根本没有那个目录:
# rpm -ql oracle-instantclient11.2-devel | grep -i sdk #
感谢您提供有关Oracle安装和使用的任何提示和任何有用的提示.有很多Oracle信息,但它通常假设Oracle安装在同一台机器上.
对于问题#1,要访问远程数据库,ORACLE_SID是无关紧要的. ORACLE_SID仅在客户端和服务器在同一主机上运行时才有用.给定tnsnames.ora文件,您应该能够使用以下命令连接到远程数据库:
sqlplus my_user@some_string
你也可以用
sqlplus my_user/my_password@some_string
但是,我通常回避在命令行上提供密码 – snoopy用户和ps命令有时可以将其丢弃.让数据库提示您输入密码.事实上,我刚刚养成了这样发出sqlplus命令的习惯:
sqlplus /nolog
然后在提示问题上
connect my_user/my_password@some_string
至于问题#2,无法帮助你.
编辑:
好吧,也许我可以帮忙#2.我找到了this link on using DBD with instant client.显然你也必须下载/安装sdk即时客户端.请参阅链接中的第3步.