php读取oracle
--第一种方法: 查询dba_tab_columns
select COLUMN_NAME,DATA_TYPE,DATA_LENGTH
from dba_tab_columns
where table_name =upper('表名')
order by COLUMN_NAME
--这种方法需要有DBA权限
--第二种方法: 查询user_tab_cols
select COLUMN_NAME,DATA_TYPE,DATA_LENGTH
from user_tab_cols
where table_name=upper('表名')
order by COLUMN_NAME
--这种方法只能查找当前用户下的表
--第三种方法: 查询ALL_TAB_COLUMNS
select distinct COLUMN_NAME,DATA_TYPE,DATA_LENGTH
from ALL_TAB_COLUMNS
WHERE TABLE_NAME= upper('表名')
--这种方法可以查询所有用户下的表
㈡ php 连接oracle数据库语句怎么写
以系统为windowns为例,
1、先PHP.INI中的oracle扩展也开启了
PHP下php.ini(注意,有时是在windows目录)修改下下
其中的
extension=php_oci8.dll 去掉前面的“;”号
extension=php_oracle.dll 去掉前面的“;”号
把php_oci8.dll 、和php_oracle.dll 文件复制到windwos的system32下
2、系统中应当有安装ORCALE的系统,然后配制远程ORACLE的的监听。就是你能用你配好的ORACLE系统访问远程的数据库。
{例:
在ORACLE安装目录下找到tnsnames.ora,然后按下面的例子配置一下
BASETEST 命名=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = XX.XX.XX.XX服务器IP地址)(PORT = 1521端口))
)
(CONNECT_DATA = (SERVICE_NAME = masprod 实例ID))
)
}
3.在你的PHP网页目录下写个测试连接的程序试试
<?php
$dbconn=OCILogon("username","pwd","(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = [远程服务器IP])(PORT = 1515))
)
(CONNECT_DATA =
(SERVICE_NAME = [数据库名字])
))");
if($dbconn!=false)
{
echo "连接成功";
if(OCILogOff($dbconn)==true)
{
echo "关闭连接成功!";//=这里有问题
}
}
else
{
echo "连接失败";
}
?>
㈢ PHP如何连接oracle数据库
首先你要在php.ini文件中找到
extension=php_oci8.dll 前面的注释符号“;”去掉,使php能够加载支持oracle的模块;
下面的代码是调试通过的,可直接使用的:
<html>
<body>
<?php
$dbconn=OCILogon("root","pass","(DESCRIPTION=(ADDRESS=(PROTOCOL =TCP)(HOST=远程IP)(PORT = 1521))(CONNECT_DATA =(SID=GZXNCW)))");
if($dbconn!=false)
{
echo "连接成功";
if(OCILogOff($dbconn)==true)
{
echo "关闭连接成功!";
}
}
else
{
echo "连接失败";
}
?>
</body>
</html>
<?php
$dbconn=oci_connect("你的账号","你的密码","你的数据库名称");//请把中文件设置为你的值;
$stmt=oci_parse($dbconn, "select * from scott.hallo");
oci_execute($stmt, OCI_DEFAULT);
echo $conn."----selecting\n\n";
while (oci_fetch($stmt))
{
echo ($conn."[".oci_result($stmt, "TEST")."]\n\n");
}
echo ($conn . "----done\n\n");
?>
㈣ 在php环境中,从oracle中获取数据如何提取具体值
连接 <? if ($conn=Ora_Logon("user@TNSNAME","password")) { echo "SUCCESS ! Connected to database\n"; }else {echo "Failed :-( Could not connect to database\n";} Ora_Logoff($conn); phpinfo(); ?>以上代码使用TNSNAME(在你的tnsnames.ora文件中指明)定义的Oracle数据库名称、用户名称和密码连接数据库。在成功连接的基础上,ora_logon函数返回一个非零的连接ID并储存在变量$conn中。 查询 假设与数据库已经连接就绪,下面我们就来实际的应用对数据库的查询。下面的代码演示了一个连接并查询的典型例子: function printoraerr($in_cur) { // 检查Oracle是否出错 // 如果存在错误则显示 // 当指针被激活时每次请求Oracle后调用该函数 if(ora_errorcode($in_cur)) echo "Oracle code - ".ora_error($in_cur)."\n"; return; } if (!($conn=ora_logon("user@TNSNAME","password"))) {echo "Connection to database failed\n"; exit; } echo "Connected as connection - $conn \n"; echo "Opening cursor ... \n"; $cursor=ora_open($conn); printoraerr($cursor); echo "Opened cursor - $cursor \n"; $qry="select user,sysdate from al"; echo "Parsing the query $qry ... \n"; ora_parse($cursor,$qry,0); printoraerr($cursor); echo "Query parsed \n"; echo "Executing cursor ... \n"; ora_exec($cursor); printoraerr($cursor); echo "Executed cursor \n"; echo "Fetching cursor ... \n"; while(ora_fetch($cursor)) { $user=ora_getcolumn($cursor,0); printoraerr($cursor); $sysdate=ora_getcolumn($cursor,1); printoraerr($cursor); echo " row = $user, $sysdate \n"; } echo "Fetched all records \n"; echo "Closing cursor ... \n"; ora_close($cursor); echo "Closed cursor \n"; echo "Logging off from oracle... \n"; ora_logoff($conn); echo "Logged off from oracle \n"; ?>显示结果以下代码演示了怎样查询数据库并将结果输出: function printoraerr($in_cur, $conn) { // 检查Oracle是否出错 // 如果存在错误则显示 // 当指针被激活时每次请求Oracle后调用该函数 // If it encountered an error, we exit immediately if(ora_errorcode($in_cur)) {echo "Oracle code - ".ora_error($in_cur)." n"; ora_logoff($conn); exit; } return; } function exequery($w_qry,$conn) { $cursor=ora_open($conn); printoraerr($cursor,$conn); ora_parse($cursor,$w_qry,0); printoraerr($cursor,$conn); ora_exec($cursor); printoraerr($cursor,$conn); $numrows=0; $w_numcols=ora_numcols($cursor); // 显示头部 echo " \n"; for ($i=0;$i<$w_numcols;$i++) { $align=(ora_columntype($cursor,$i)=="NUMBER")?"RIGHT":"LEFT"; echo "\t ".ora_columnname($cursor,$i)." \n"; } echo " \n"; while(ora_fetch($cursor)) { echo " \n"; for ($i=0;$i<$w_numcols;$i++) { $align=(ora_columntype($cursor,$i)=="NUMBER")?"RIGHT":"LEFT"; if(ora_columntype($cursor,$i)=="LONG") echo " ". ora_getcolumn($cursor,$i)." \n"; else echo " ".ora_getcolumn($cursor,$i)." \n"; printoraerr($cursor,$conn); } $numrows++; echo " \n"; } if ($numrows==0) echo " Query returned no records \n"; else { echo " \n"; echo " Count \n"; echo " $numrows \n"; echo " \n"; } echo " \n"; ora_close($cursor); return; } // 主程序 if(!($conn=ora_logon("user@SID","password"))) { echo "Error: Cannot connect to database\n"; exit; } $qry="SELECT deptno \"Dept\" ,empno \"Emp\" ,empnm \"Name\" ,salary \"Salary\" FROM employee ORDER BY 1,2"; exequery($qry); ora_logoff($conn); ?>基于HTTP的Oracle登录将以下代码加在PHP页面代码之前以确认Oracle登录。注意你必须正确设定$ SID。 if(!isset($PHP_AUTH_USER)) { Header("WWW-authenticate: basic realm=\"$SID\""); Header("HTTP/1.0 401 Unauthorized"); $title="Login Instructions"; echo " You are not authorized to enter the site \n"; exit; } else { if (!($conn=ora_logon("$PHP_AUTH_USER@$SID",$PHP_AUTH_PW))) {Header("WWW-authenticate: basic realm=\"$SID\""); Header("HTTP/1.0 401 Unauthorized"); $title="Login Instructions"; echo " You are not authorised to enter the site \n"; exit; }} ?>
㈤ PHP怎么连接并操作远程ORACLE数据库
putenv ("ORACLE_BASE=/ora");
putenv ("ORACLE_HOME=/ora");
putenv("NLS_LANG=AMERICAN");
//$conn = Ora_PLogon("hostname","passwd");
$conn = Ora_PLogon("web@web","web");
@ora_commiton($conn);
$cur=ora_open($conn);
$err_no=0;
$query = "select PASSWORD from register where mobilno='$t_tele_num'";
$result=ora_parse($cur,$query);
$result=ora_exec($cur);
if(ora_fetch($cur))
$datacount = ora_getcolumn($cur, 0);
echo "$datecount";
ora_close($cur);
㈥ php调用oracle存储过程与函数
对于存储过程的源代码,开始都需要先定义接受的参数,例如:
PROCEDURE edit_entry(
status_out OUT NUMBER,
status_msg_out OUT VARCHAR2,
id_inout IN OUT INTEGER,
title_in IN VARCHAR2,
text_out OUT CLOB,
categories_in IN list_of_numbers
);
从 PHP 中调用存储过程 对于要从 PHP 中执行以调用过程的 SQL 语句而言,您将通常在 Oracle BEGIN ...END; 块(称作匿名块)中嵌入调用。例如:
<?php
// etc.
//$sql = 'BEGIN sayHello(:name, :message); END;';
//然后,通过调用 oci_bind_by_name() 将参数绑定到 PHP 变量。 如果使用以下 DDL 语句定义了 sayHello
//:
//CREATE OR REPLACE PROCEDURE
//sayHello (name IN VARCHAR2, greeting OUT VARCHAR2)
//AS
//BEGIN
//greeting := 'Hello ' || name;
//END;
//
//注意,您可以使用 SQL*Plus 命令行运行上面的语句。将该语句保存到文件 (SAYHELLO.SQL)。接下来,使用
//SQL*Plus 登录:
//$ sqlplus username@SID
//然后,使用 START 命令创建该过程:
//SQL> START /home/username/SAYHELLO.SQL
//以下 PHP 脚本调用该过程:$conn = oci_connect('SCOTT','TIGER') or die;
$sql = 'BEGIN sayHello(:name, :message); END;';
$stmt = oci_parse($conn,$sql);
// Bind the input parameter
oci_bind_by_name($stmt,':name',$name,32);
// Bind the output parameter
oci_bind_by_name($stmt,':message',$message,32);
// Assign a value to the input
$name = 'Harry';
oci_execute($stmt);
// $message is now populated with the output value
print "$message\n";
?>
调用程序包中的过程时,将使用句号来分隔程序包名称与过程名称。 可以使用以下语句指定 blog 程序包:
CREATE OR REPLACE PACKAGE blog AS
TYPE cursorType IS REF CURSOR RETURN blogs%ROWTYPE;
/*
Fetch the latest num_entries_in from the blogs table, populating
entries_cursor_out with the result
*/
PROCEDURE latest(
num_entries_in IN NUMBER,
entries_cursor_out OUT cursorType
);
/*
Edit a blog entry.If id_inout is NULL, results in an INSERT, otherwise
attempts to UPDATE the existing blog entry. status_out will have the value
1 on success, otherwise a negative number on failure with status_msg_out
containing a description
categories_in is a collection where list_of_numbers is described by
TYPE list_of_numbers AS VARRAY(50) OF NUMBER;
*/
PROCEDURE edit_entry(
status_out OUT NUMBER,
status_msg_out OUT VARCHAR2,
id_inout IN OUT INTEGER,
title_in IN VARCHAR2,
text_out OUT CLOB,
categories_in IN list_of_numbers
);
END blog;
/
㈦ php访问oracle数据库问题
hzds_user是用户名,对应界面上的用户名
oracle是数据库名,对应界面上的hzds_oracle
hzds是服务名,对应界面上的服务名hzds
㈧ php调用oracle存储过程读取数据,怎么写呀,如果返回值是一个数组呢,还有怎么传值呀
http://www.jcwcn.com/article-15176-1.html
参考一下
㈨ 如何让PHP支持Oracle
使你的php支持oracle,按照以下步骤即可:
1.安装php环境,找一下appserv或者xampp,一键安装,很方便
2.把php的ext目录下的php_oci8.dll拷到system32目录下
3.修改php.ini文件中的配置,去掉 ;extention = php_oci8.dll,去掉前面的分号
4.重启apache
两种方式和oracle数据库建立链接
1.$conn = oci_connect('username','password',"(DEscriptION=(ADDRESS=(PROTOCOL =TCP)(HOST=192.168.1.100)(PORT = 1521))(CONNECT_DATA =(SID=test)))");
2.$conn = oci_connect('username','password','192.168.1.100/test');
有的时候第一种方式不行,使用第二种,里面的几个参数分别是用户名、密码、oracle服务地址,其中test是服务名。
$sql = "select * from table_exmaple"
$ora_test = oci_parse($conn,$sql); //编译sql语句
oci_execute($ora_test,OCI_DEFAULT); //执行
while($r=oci_fetch_row($ora_test)) //取回结果
{
echo $ora_test[0];
echo "<BR>";
}
改成这样试下:
$dbconn = oci_connect('用户名','密码',"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.136.1.10)(PORT=1521))(CONNECT_DATA=(SID=pmsbp)))");