類別 DB_Sql {
var $調試=假;
var $Home = "/u01/app/Oracle/PROdduct/8.0.4";
var $Remote = 1;
/* 該查詢將在第一次連接後直接發送
例:
var $ConnectQuery="ALTER session SET nls_date_language=德語 nls_date_format='DD.MM.RRRR'";
->設定此會話的日期格式,當您的 ora-role 時這很好
無法更改*/
var $ConnectQuery='';
/* 由於 Oracle 8.0.5、Apache 和 php3.0.6 出現奇怪的錯誤
你不需要在我的系統 Apache 上設定 ENV
如果我不將其設為 FALSE,將會變成殭屍!
相反,我在 apache 啟動之前設定了這些 ENV-vars。
如果不確定,請嘗試一下,如果有效的話。 */
var $OraPutEnv = true;
var $資料庫 = "";
var $User = "";
var $PassWord = "";
var $Link_ID = 0;
var $Query_ID = 0;
var $Record = array();
var $Row;
var $Errno = 0;
var $Error = "";
var $ora_no_next_fetch=false;
/* 為了完整性而從 db_MySQL 複製 */
/* public: 辨識常數。永遠不要改變這一點。 */
var $type = "甲骨文";
var $revision = "修訂版: 1.3";
var $Halt_On_Error = "是"; ## “是”(停止並顯示訊息),“否”(安靜地忽略錯誤),“報告”(忽略錯誤,但發出警告)
/* 公用:建構子 */
函數 DB_Sql($query = "") {
$this->查詢($query);
}
/* public: 一些瑣碎的報告 */
函數 link_id() {
返回 $this->Link_ID;
}
函數 query_id() {
返回 $this->Query_ID;
}
函數連接() {
## 參見上文我們為什麼要這樣做
if ($this->OraPutEnv) {
PutEnv("ORACLE_SID=$this->資料庫");
PutEnv("ORACLE_HOME=$this->Home");
}
if ( 0 == $this->Link_ID ) {
if($this->調試) {
printf("
連接()到$this->資料庫...
n");
}
if($this->Remote) {
if($this->調試) {
printf("
connect() $this->User/******@$this->資料庫
n");
}
$this->Link_ID=ora_plogon
("$this->使用者/$this->密碼@$this->資料庫","");
/****************(SSilk 評論)
這在我的系統上不起作用:
$this->Link_ID=ora_plogon
("$this->User@$this->Database.world","$this->Password");
***************/
} 其他 {
if($this->調試) {
printf("
connect() $this->用戶, $this->密碼
n");
}
$this->Link_ID=ora_plogon("$this->使用者","$this->密碼");
/* (SSilk 的評論:不知道這是如何工作的,但我保持不變!)*/
}
if($this->調試) {
printf("
connect() Link_ID: $this->Link_ID
n");
}
if (!$this->Link_ID) {
$this->halt("connect() Link-ID == false " .
"($this->Link_ID), ora_plogon 失敗");
} 其他 {
//echo “提交
”;
以上就介紹了php的oracle資料庫函式庫,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。
ora_commiton($this->Link_ID);
}
if($this->調試) {
printf("
connect() 取得 Link_ID: $this->Link_ID
n");
}
## 執行連線查詢
if ($this->ConnectQuery) {
$this->query($this->ConnectQuery);
}
}
}
## 為了增加每個系統/使用者的遊標數量,請編輯
## init.ora檔案並增加max_open_cursors參數。你的已開啟
## 預設值,每個使用者 100 個。
## 我們嘗試以某種方式改變 query() 的行為,它嘗試
## 確保遊標安全,但另一方面要小心,你
## 不要使用舊的結果。
##
## 您也可以廣泛使用->disconnect()!
## 未使用的QueryID有時會被回收。
函數查詢($Query_String)
{
/* 請不要有空查詢。 */
如果(空($Query_String))
{
返回 0;
}
$this->connect();
$this->lastQuery=$Query_String;
if (!$this->Query_ID) {
$this->Query_ID= ora_open($this->Link_ID);
}
if($this->調試) {
printf("調試:查詢 = %s
n", $Query_String);
printf("
調試:Query_ID:%d
n",$this->Query_ID);
}
if(!@ora_parse($this->Query_ID,$Query_String)) {
$this->Errno=ora_errorcode($this->Query_ID);
$this->Error=ora_error($this->Query_ID);
$this->halt("
ora_parse() 失敗:
$Query_String
將其貼到 sqlplus!");
} elseif (!@ora_exec($this->Query_ID)) {
$this->Errno=ora_errorcode($this->Query_ID);
$this->Error=ora_error($this->Query_ID);
$this->halt("
n$Query_Stringn
將其貼到 sqlplus!");
}
$這->行=0;
if(!$this->Query_ID) {
$this->halt("無效的 SQL: ".$Query_String);
}
返回 $this->Query_ID;
}
函數 next_record() {
if (!$this->ora_no_next_fetch &&
0 == ora_fetch($this->Query_ID)) {
if ($this->調試) {
printf("
next_record(): ID: %d 行: %d
n",
$this->Query_ID,$this->Row+1);
// $this->Row+1 的更多資訊是 $this->num_rows(),
// 但並非在所有情況下都有效(複雜的選擇)
// 這裡速度很慢
}
$this->行+=1;
$errno=ora_errorcode($this->Query_ID);
if(1403 == $errno) { # 1043 表示找不到更多記錄
$this->Errno=0;
$this->Error="";
$this->disconnect();
$統計=0;
} 其他 {
$this->Error=ora_error($this->Query_ID);
$this->Errno=$errno;
if($this->調試) {
printf("
%d 錯誤:%s",
$this->Errno,
$this->錯誤);
}
$統計=0;
}
} 其他 {
$this->ora_no_next_fetch=false;
for($ix=0;$ix
$col=strtolower(ora_columnname($this->Query_ID,$ix));
$value=ora_getcolumn($this->Query_ID,$ix);
$this->Record[ "$col" ] = $value;
$this->Record[ $ix ] = $value;
#DBG echo"[$col]: $value
n";
}
$統計=1;
}
返回$stat;
}
##eek() 僅適用於 $pos - 1 和 $pos
## 也許我自己實現了,但是我的
## 意見是,這應該由 PHP3 來完成
函數查找($pos) {
if ($this->Row - 1 == $pos) {
$this->ora_no_next_fetch=true;
} elseif ($this->Row == $pos ) {
## 什麼都不做
} 其他 {
$this->halt("seek() 無效:API 無法處理位置。
"。
「此版本中僅允許尋找最後一個元素
」。
"差異太大。想要:$pos 目前位置:$this->Row");
}
if ($this->Debug) echo "
調試:seek = $pos
";
$this->Row=$pos;
}
函數鎖定($table, $mode = "write") {
if ($mode == "write") {
$result = ora_do($this->Link_ID, "以行獨佔模式鎖定表格$table");
} 其他 {
$結果= 1;
}
回 $ 結果;
}
函數解鎖() {
return ora_do($this->Link_ID, "commit");
}
// 重要:此函數不適用於 Oracle-Database-Links!
// 你可以自由地獲得更好的方法。 :)
函數元資料($table,$full=false) {
$計數 = 0;
$id = 0;
$res = 陣列();
/*
* 由於與 Table 的兼容性問題,我們更改了行為
* 元資料();
* 根據 $full,元資料傳回下列值:
*
* - full 為 false(預設):
* $結果[]:
* [0]["table"] 表名
* [0]["name"] 欄位名稱
* [0]["type"] 欄位類型
* [0]["len"] 字段長度
* [0]["flags"] 欄位標誌 ("NOT NULL", "INDEX")
* [0]["format"] 數字的精確度和小數位數(例如「10,2」)或空
* [0]["index"] 索引名稱(如果有的話)
* [0]["chars"] 字元數(如果有字元型別)
*
* - 完整是真的
* $結果[]:
* ["num_fields"] 元資料記錄數
* [0]["table"] 表名
* [0]["name"] 欄位名稱
* [0]["type"] 欄位類型
* [0]["len"] 字段長度
* [0]["flags"] 欄位標誌 ("NOT NULL", "INDEX")
* [0]["format"] 數字的精確度和小數位數(例如「10,2」)或空
* [0]["index"] 索引名稱(如果有的話)
* [0]["chars"] 字元數(如果有字元型別)
* [0]["php_type"] 對應的 PHP 類型
* [0]["php_subtype"] PHP 類型的子型別
* ["meta"][field name] 名為「field name」的欄位索引
* 如果你有名字,但沒有索引號,這可以使用 - 非常快
* 測試: if (isset($result['meta']['myfield'])) {} ...
*/
$this->connect();
## 這是一個右外連接:“(+)”,如果你想看的話,什麼
## 此查詢結果嘗試以下操作:
## $table = 新表; $db = 新的 my_DB_Sql; #你必須要做
## #你自己的班級
## $table->show_results($db->query(參見查詢 vvvvvv))
##
$this->query("SELECT T.table_name,T.column_name,T.data_type,".
「T.data_length,T.data_ precision,T.data_scale,T.nullable,」。
「T.char_col_decl_length,I.index_name」。
「來自 ALL_TAB_COLUMNS T,ALL_IND_COLUMNS I」。
「其中 T.column_name=I.column_name (+)」。
「 AND T.table_name=I.table_name (+)」。
“ AND T.table_name=UPPER('$table') ORDER BY T.column_id");
$i=0;
while ($this->next_record()) {
$res[$i]["table"] = $this->Record[table_name];
$res[$i]["name"] = strtolower($this->Record[column_name]);
$res[$i]["type"] = $this->Record[data_type];
$res[$i]["len"] = $this->Record[data_length];
if ($this->Record[index_name]) $res[$i]["flags"] = "INDEX ";
$res[$i]["flags"] .= ( $this->Record[nullable] == 'N') ? '':'非空';
$res[$i]["format"]= (int)$this->Record[data_ precision].",".
(int)$this->記錄[data_scale];
if ("0,0"==$res[$i]["格式"]) $res[$i]["格式"]='';
$res[$i]["index"] = $this->Record[index_name];
$res[$i]["chars"] = $this->Record[char_col_decl_length];
如果($滿){
$j=$res[$i]["名稱"];
$res["元"][$j] = $i;
$res["元"][strtoupper($j)] = $i;
開關 ($res[$i]["類型"]) {
案例“VARCHAR2”:
案例“VARCHAR”:
案例“CHAR”:
$res["php_type"]="字串";
$res["php_subtype"]="";
休息;
案例“日期”:
$res["php_type"]="字串";
$res["php_subtype"]="日期";
休息;
案例“BLOB”:
案例“CLOB”:
案例“BFILE”:
案例“RAW”:
案例「長」:
案例“長原始”:
$res["php_type"]="字串";
$res["php_subtype"]="blob";
休息;
案例「編號」:
if ($res[$i]["格式"]) {
$res["php_type"]="雙";
$res["php_subtype"]="";
} 其他 {
$res["php_type"]="int";
$res["php_subtype"]="";
}
休息;
預設:
$this->halt("metadata(): 類型不是有效值: '$res[$i][type]'");
休息;
}
}
if ($full) $res["元"][$res[$i]["名稱"]] = $i;
$i++;
}
if ($full) $res["num_fields"]=$i;
# $this->disconnect();
返回 $res;
}
## 此功能未經測試!
函數受影響的行(){
if ($this->Debug) echo "
調試:affected_rows="。 ora_numrows($this->Query_ID)."
";
return ora_numrows($this->Query_ID);
}
## 已知錯誤:它不適用於 SELECT DISTINCT 和任何
## 其他結構取決於結果行。
## 所以你*真的需要*檢查你所做的每個查詢,如果是的話
## 將與它一起工作!
##
## 此外,對於合格的替換,您需要解析
## 選擇,因為這將會失敗:「SELECT id, from FROM ...」)。
## “from” 是 - 據我所知 Oracle 中的一個關鍵字,所以它可以
##只能這樣使用。但你已經被警告過。
函數 num_rows() {
$curs=ora_open($this->Link_ID);
## 這是重要的部分,也是HACK!
if (eregi("^[[:space:]]*SELECT[[:space:]]",$this->lastQuery) )
{
# 這對所有人都有效?情況,包括 SELECT DISTINCT 情況。
# 我們只是從原始 sql 表達式中選擇 count(*)
# 並刪除 ORDER BY(如果有)以提高速度
# 我也喜歡正規表示式 ;-)))
$q = sprintf("從 (%s) 選擇 COUNT(*) 個",
@eregi_Replace("ORDER[[:space:]]+BY[^)]*()*)", "1",
$this->lastQuery)
);
# 也適用於子選擇:
# if (eregi("[[:space:]]+FROM([[:space:]]+.*[[:space:]]+FROM)",$this->lastQuery,$r))
# $areplace=$r[1];
# $q=eregi_Replace("^[[:space:]]*SELECT[[:space:]]+".
# ".*[[:空格:]]+FROM",
# "從 $areplace 中選擇 COUNT(*) 個",
# $this->lastQuery);
if ($this->Debug) echo "
調試:num_rows: $q
";
ORA_parse($curs,$q);
ORA_exec($curs);
ORA_fetch($curs);
$結果 = ORA_getcolumn($curs,0);
ORA_close($curs);
if ($this->調試)
{
echo "
調試:ID ".$this->QueryID。
“行數=”。 $結果 ."
";
}
回 $ 結果;
}
否則
{
$this->halt("最後一個查詢不是 SELECT: $this->lastQuery");
}
}
函數 num_fields() {
if ($this->Debug) echo "
Debug: num_fields=". ora_numcols($this->Query_ID) 。 “
”;
return ora_numcols($this->Query_ID);
}
函數 nf() {
返回 $this->num_rows();
}
函數 np() {
印出 $this->num_rows();
}
函數 f($Name) {
return $this->Record[$Name];
}
函數 p($Name) {
print $this->Record[$Name];
}
/* public: 序號 */
函數 nextid($seq_name)
{
$this->connect();
/* 獨立的Query_ID */
$Query_ID = ora_open($this->Link_ID);
if(!@ora_parse($Query_ID,"SELECT $seq_name.NEXTVAL FROM DUAL"))
{
// 還沒有這樣的序列,那就創建它
if(!@ora_parse($Query_ID,"建立序列 $seq_name")
||
!@ora_exec($Query_ID)
)
{
$this->halt("
nextid() 函數 - 無法建立序列");
返回 0;
}
@ora_parse($Query_ID,"從 DUAL 選擇 $seq_name.NEXTVAL");
}
if (!@ora_exec($Query_ID)) {
$this->halt("
ora_exec() 失敗:
nextID 函數");
}
if (@ora_fetch($Query_ID) ) {
$next_id = ora_getcolumn($Query_ID, 0);
}
否則{
$next_id = 0;
}
if ( $Query_ID > 0 ) {
ora_close($Query_ID);
}
返回$next_id;
}
函數斷開連接(){
if($this->調試) {
echo "調試:斷開 $this->Query_ID...
n";
}
if ( $this->Query_ID
echo "警告:斷開連接():無法釋放 ID $this->Query_IDn";
# 返回();
}
ora_close($this->Query_ID);
$this->Query_ID=0;
}
/* 私有:錯誤處理 */
函數暫停($msg){
if ($this->Halt_On_Error == "no")
返回;
$this->haltmsg($msg);
if ($this->Halt_On_Error != "報告")
die("會話已停止。");
}
函數haltmsg($msg) {
printf("
資料庫錯誤:%s
n", $msg);
printf("Oracle 錯誤: %s (%s)
n",
$this->Errno,
$this->錯誤);
}
函數表名() {
$this->connect();
$this->查詢("
選擇表名,表空間名
來自用戶表");
$i=0;
while ($this->next_record())
{
$info[$i]["table_name"] =$this->Record["table_name"];
$info[$i]["tablespace_name"]=$this->Record["tablespace_name"];
$i++;
}
返回$ 資訊;
}
// 一些交易支援
// ct_oracle.inc 中使用的方法
函數 begin_transaction()
{
$this->connect();
// 現在,停用自動提交
Ora_CommitOff($this->Link_ID);
if ($this->調試)
{
列印“開始交易
”;
}
}
函數 end_transaction()
{
if ($this->調試)
{
列印“開始交易
”;
}
$res = 1;
if(!@Ora_Commit($this->Link_ID))
{
Ora_CommitOn($this->Link_ID);
$this->halt("無法完成交易");
$res = 0;
}
// 再次啟用自動提交
Ora_CommitOn($this->Link_ID);
if ($this->調試)
{
print "結束事務:$res
";
}
返回 $res;
}
}
? >

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

PHP不是在消亡,而是在不斷適應和進化。 1)PHP從1994年起經歷多次版本迭代,適應新技術趨勢。 2)目前廣泛應用於電子商務、內容管理系統等領域。 3)PHP8引入JIT編譯器等功能,提升性能和現代化。 4)使用OPcache和遵循PSR-12標準可優化性能和代碼質量。

PHP的未來將通過適應新技術趨勢和引入創新特性來實現:1)適應云計算、容器化和微服務架構,支持Docker和Kubernetes;2)引入JIT編譯器和枚舉類型,提升性能和數據處理效率;3)持續優化性能和推廣最佳實踐。

在PHP中,trait適用於需要方法復用但不適合使用繼承的情況。 1)trait允許在類中復用方法,避免多重繼承複雜性。 2)使用trait時需注意方法衝突,可通過insteadof和as關鍵字解決。 3)應避免過度使用trait,保持其單一職責,以優化性能和提高代碼可維護性。

依賴注入容器(DIC)是一種管理和提供對象依賴關係的工具,用於PHP項目中。 DIC的主要好處包括:1.解耦,使組件獨立,代碼易維護和測試;2.靈活性,易替換或修改依賴關係;3.可測試性,方便注入mock對象進行單元測試。

SplFixedArray在PHP中是一種固定大小的數組,適用於需要高性能和低內存使用量的場景。 1)它在創建時需指定大小,避免動態調整帶來的開銷。 2)基於C語言數組,直接操作內存,訪問速度快。 3)適合大規模數據處理和內存敏感環境,但需謹慎使用,因其大小固定。

PHP通過$\_FILES變量處理文件上傳,確保安全性的方法包括:1.檢查上傳錯誤,2.驗證文件類型和大小,3.防止文件覆蓋,4.移動文件到永久存儲位置。

JavaScript中處理空值可以使用NullCoalescingOperator(??)和NullCoalescingAssignmentOperator(??=)。 1.??返回第一個非null或非undefined的操作數。 2.??=將變量賦值為右操作數的值,但前提是該變量為null或undefined。這些操作符簡化了代碼邏輯,提高了可讀性和性能。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)