Home > php教程 > php手册 > body text

php连接oracle百发百中问题解决秘籍

WBOY
Release: 2016-06-06 19:45:48
Original
1281 people have browsed it

最近要使用php连接oracle,被折腾死了。最后终于全部搞定,现将探索过程和解决方法公布出来。 1. 首先安装 oracle 的客户端 ,instantclient10_1 将其中的 dll 文件拷贝放入 c:/oracle( 自己随便取得 ) 将 c:/oracle 放入环境变量 PATH 里 , 一定要重新启动 ap

 最近要使用php连接oracle,被折腾死了。最后终于全部搞定,现将探索过程和解决方法公布出来。

 

1.首先安装oracle 的客户端,instantclient10_1

将其中的dll文件拷贝放入c:/oracle(自己随便取得)

c:/oracle放入环境变量PATH,一定要重新启动apache

php里配置库,打开选项

extension=php_oci8.dll

 

秘方:如果提示oracle扩展没加载上,直接把oracledll文件copyapachebin目录下就可以。

2.配置oracle

a.建立帐号

 CREATE USER "DONG"  PROFILE "DEFAULT"

    IDENTIFIED BY "dong" DEFAULT TABLESPACE "USERS"

    ACCOUNT UNLOCK;

b.赋予权限

 GRANT "CONNECT",SELECT,resource  TO "DONG"

c.建立表空间

CREATE TABLESPACE "dong"

LOGGING

DATAFILE '/usr/oracle/10.2/dbs/dong.ora' SIZE 5M EXTENT

MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT  AUTO;

 

 

 

d.表空间和用户关联

ALTER USER "DONG"  DEFAULT TABLESPACE "dong";

 

e.建立一个表测试

create table DONG.test (test varchar(20));

 

3.得到连接的数据库id

select instance_name from v$instance ;

 

4.程序如下:

$ora_db_host = '192.168.123.223';

$ora_db_port = 1521;

$ora_db_name = 'DONG';

$ora_db_user = 'DONG';

$ora_db_pswd = 'dong';

$ora_db_sid = 'orcl';//3 的方法得到的

 

$db = "(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = $ora_db_host)(PORT = $ora_db_port))

(CONNECT_DATA = (SID = $ora_db_sid)))";

 

 

$ora_conn = oci_connect($ora_db_user , $ora_db_pswd, $db);

 

秘方1:如果提示ORA-12541: TNS:no listener ,则到oracle服务端找到listener.ora,添加入自己的数据源定义

:

(SID_DESC =

    (GLOBAL_DBNAME = dong)

    (ORACLE_HOME = /usr/oracle/10.2)

    (SID_NAME = orcl)

 

  )

然后命令行下执行

lsnrctl

进入命令行后,

LSNRCTL>   stop;

LSNRCTL>   start;

如果还没搞定,listener.ora里还有个地方很关键:

(ADDRESS = (PROTOCOL = TCP)(HOST = xxxx)(PORT = 1521))

通常HOST都写为localhost,如果你要从外连过来,死都连接不成,想想为啥,

从外部连过来只要将HOST 换为对应地址就可以了,然后重新

lsnrctl

进入命令行后,

LSNRCTL>   stop;

LSNRCTL>   start;

 

 

秘方2:如果提示ORA-01045:user xxx lacks CREATE SESSION privilege;logon denied.就是2grant没到位

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template