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)))");