下载
instantclient-basic-win32-10.2.0.4.zip
instantclient-basic下载地址:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
将instantclient-basic-win32-10.2.0.4.zip解压出来的文件拷贝到 c:/windows/system32/目录下
配置php.ini
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client
;extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
连接:
function connect(){
try{
$pdo = new PDO('oci:dbname=114.242.113.91:1521/orcl', 'user','pwd');
return $pdo;
}catch(PDOException $e){
echo '数据库连接出错:'.$e->getMessage();
return false;
}
}
$pdo = connect();
$sql = 'SELECT * from LOGININFO';
$re = $pdo->query($sql)->fetchAll();
var_dump($re);
linux环境还可参考:
http://blog.csdn.net/nailwl/article/details/4987127
http://www.sudu.cn/info/html/edu/20070102/283519.html
http://iceeggplant.blog.51cto.com/1446843/1052512/
http://netyum.blog.163.com/blog/static/1417502201092411547491/
Ø 本次开发环境是CentOS64,需要软件:
http://ishare.iask.sina.com.cn/download/explain.php?fileid=33768478
oracle-instantclient-basic-10.2.0.4-1.i386.rpm
oracle-instantclient-devel-10.2.0.4-1.i386.rpm
oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm
Ø 设置环境变量
$ whereis oracle
vi/root/.bash_profile
添加export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:[oraclelibdir]
///类似’/usr/lib/oracle/11.2/client/lib ‘
保存退出
source/root/.bash_profile
ª php 扩展安装
pdo_oci 与 oci8 包
² oci8 包安装
# cd /root/php-5.3.1/ext/oci8
# /usr/local/php5/bin/phpize
# ./configure --with-oci8=instantclient,/usr/lib/oracle/10.2.0.4/client/lib/--with-php-config=/usr/local/php5/bin/php-config
# make && make install
² pdo_oci包安装
# cd /root/php-5.3.1/ext/pdo_oci
# /usr/local/php5/bin/phpize
# ./configure --with-php-config=/usr/local/php5/bin/php-config --with-pdo-oci=instantclient,/usr,10.2.0.4
# make && make install
# vi /usr/local/php5/php.ini 添加以下内容
extension=pdo.so
extension=pdo_oci.so
extension=oci8.so