位置: 编程技术 - 正文

PHP:oci_fetch_array()的用法_Oracle函数

编辑:rootadmin
oci_fetch_array

推荐整理分享PHP:oci_fetch_array()的用法_Oracle函数,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

(PHP 5, PECL OCI8 >= 1.1.0)

oci_fetch_array — Returns the next row from a query as an associative or numeric array

说明 array oci_fetch_array ( resource $statement [, int $mode ] )

Returns an array containing the next result-set row of a query. Each array entry corresponds to a column of the row. This function is typically called in a loop until it returns FALSE, indicating no more rows exist.

If statement corresponds to a PL/SQL block returning Oracle Database c Implicit Result Sets, then rows from all sets are consecutively fetched. If statement is returned by oci_get_implicit_resultset(), then only the subset of rows for one child query are returned.

要获取 OCI8扩展进行数据类型映射的细节,请参见驱动所支持的数据类型。

参数

statement

有效的 OCI8 报表标识符由 oci_parse() 创建,被 oci_execute()或 REF CURSOR statement 标识执行。

Can also be a statement identifier returned by oci_get_implicit_resultset().

mode

An optional second parameter can be any combination of the following constants: oci_fetch_array() Modes Constant Description OCI_BOTH Returns an array with both associative and numeric indices. This is the same as OCI_ASSOC + OCI_NUM and is the default behavior. OCI_ASSOC Returns an associative array. OCI_NUM Returns a numeric array. OCI_RETURN_NULLS Creates elements for NULL fields. The element values will be a PHP NULL. OCI_RETURN_LOBS Returns the contents of LOBs instead of the LOB descriptors.

The default mode is OCI_BOTH.

Use the addition operator "+" to specify more than one mode at a time.

返回值

Returns an array with associative and/or numeric indices. If there are no more rows in the statement then FALSE is returned.

By default, LOB columns are returned as LOB descriptors.

DATE columns are returned as strings formatted to the current date format. The default format can be changed with Oracle environment variables such as NLS_LANG or by a previously executed ALTER SESSION SET NLS_DATE_FORMAT command.

Oracle&#;s default, non-case sensitive column names will have uppercase associative indices in the result array. Case-sensitive column names will have array indices using the exact column case. Use var_dump() on the result array to verify the appropriate case to use for each query.

The table name is not included in the array index. If your query contains two different columns with the same name, use OCI_NUM or add a column alias to the query to ensure name uniqueness, see example #7. Otherwise only one column will be returned via PHP.

范例

Example #1 oci_fetch_array() with OCI_BOTH

<?php$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$e=oci_error();trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);}$stid=oci_parse($conn,'SELECTdepartment_id,department_nameFROMdepartments');oci_execute($stid);while(($row=oci_fetch_array($stid,OCI_BOTH))!=false){//Usetheuppercasecolumnnamesfortheassociativearrayindicesecho$row[0]."and".$row['DEPARTMENT_ID']."arethesame<br>n";echo$row[1]."and".$row['DEPARTMENT_NAME']."arethesame<br>n";}oci_free_statement($stid);oci_close($conn);?>

Example #2 oci_fetch_array() with OCI_NUM

<?php/*Beforerunning,createthetable:CREATETABLEmytab(idNUMBER,descriptionCLOB);INSERTINTOmytab(id,description)values(1,'Averylongstring');COMMIT;*/$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$e=oci_error();trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);}$stid=oci_parse($conn,'SELECTid,descriptionFROMmytab');oci_execute($stid);while(($row=oci_fetch_array($stid,OCI_NUM))!=false){echo$row[0]."<br>n";echo$row[1]->read()."<br>n";//thiswilloutputfirstbytesfromDESCRIPTION}//

Example #3 oci_fetch_array() with OCI_ASSOC

<?php/*Beforerunning,createthetable:CREATETABLEmytab(idNUMBER,descriptionCLOB);INSERTINTOmytab(id,description)values(1,'Averylongstring');COMMIT;*/$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$e=oci_error();trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);}$stid=oci_parse($conn,'SELECTid,descriptionFROMmytab');oci_execute($stid);while(($row=oci_fetch_array($stid,OCI_ASSOC))!=false){echo$row['ID']."<br>n";echo$row['DESCRIPTION']->read()."<br>n";//thiswilloutputfirstbytesfromDESCRIPTION}//

PHP:oci_fetch_array()的用法_Oracle函数

Example #4 oci_fetch_array() with OCI_RETURN_NULLS

<?php$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$e=oci_error();trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);}$stid=oci_parse($conn,'SELECT1,nullFROMdual');oci_execute($stid);while(($row=oci_fetch_array($stid,OCI_ASSOC))!=false){//IgnoreNULLsvar_dump($row);}/*Theabovecodeprints:array(1){[1]=>string(1)"1"}*/$stid=oci_parse($conn,'SELECT1,nullFROMdual');oci_execute($stid);while(($row=oci_fetch_array($stid,OCI_ASSOC+OCI_RETURN_NULLS))!=false){//FetchNULLsvar_dump($row);}/*Theabovecodeprints:array(2){[1]=>string(1)"1"["NULL"]=>NULL}*/?>

Example #5 oci_fetch_array() with OCI_RETURN_LOBS

<?php/*Beforerunning,createthetable:CREATETABLEmytab(idNUMBER,descriptionCLOB);INSERTINTOmytab(id,description)values(1,'Averylongstring');COMMIT;*/$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$e=oci_error();trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);}$stid=oci_parse($conn,'SELECTid,descriptionFROMmytab');oci_execute($stid);while(($row=oci_fetch_array($stid,OCI_ASSOC+OCI_RETURN_LOBS))!=false){echo$row['ID']."<br>n";echo$row['DESCRIPTION']."<br>n";//thiscontainsallofDESCRIPTION//Inaloop,freeingthelargevariablebeforethe2ndfetchreducesPHP'speakmemoryusageunset($row);}//

Example #6 oci_fetch_array() with case sensitive column names

<?php/*Beforerunning,createthetable:CREATETABLEmytab("Name"VARCHAR2(),cityVARCHAR2());INSERTINTOmytab("Name",city)values('Chris','Melbourne');COMMIT;*/$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$e=oci_error();trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);}$stid=oci_parse($conn,'select*frommytab');oci_execute($stid);$row=oci_fetch_array($stid,OCI_ASSOC+OCI_RETURN_NULLS);//Because'Name'wascreatedasacase-sensitivecolumn,thatsame//caseisusedforthearrayindex.Howeveruppercase'CITY'must//beusedforthecase-insensitivecolumnindexprint$row['Name']."<br>n";//printsChrisprint$row['CITY']."<br>n";//printsMelbourneoci_free_statement($stid);oci_close($conn);?>

Example #7 oci_fetch_array() with columns having duplicate names

<?php/*Beforerunning,createthetables:CREATETABLEmycity(idNUMBER,nameVARCHAR2());INSERTINTOmycity(id,name)values(1,'Melbourne');CREATETABLEmycountry(idNUMBER,nameVARCHAR2());INSERTINTOmycountry(id,name)values(1,'Australia');COMMIT;*/$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$e=oci_error();trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);}$sql='SELECTmycity.name,mycountry.nameFROMmycity,mycountryWHEREmycity.id=mycountry.id';$stid=oci_parse($conn,$sql);oci_execute($stid);$row=oci_fetch_array($stid,OCI_ASSOC);var_dump($row);//Outputonlycontainsone"NAME"

Example #8 oci_fetch_array() with DATE columns

<?php$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$e=oci_error();trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);}//Setthedateformatforthisconnection.//Forperformancereasons,considerchangingtheformat//inatriggerorwithenvironmentvariablesinstead$stid=oci_parse($conn,"ALTERSESSIONSETNLS_DATE_FORMAT='YYYY-MM-DD'");oci_execute($stid);$stid=oci_parse($conn,'SELECThire_dateFROMemployeesWHEREemployee_id=');oci_execute($stid);$row=oci_fetch_array($stid,OCI_ASSOC);echo$row['HIRE_DATE']."<br>n";//prints--oci_free_statement($stid);oci_close($conn);?>

Example #9 oci_fetch_array() with REF CURSOR

<?php/*CreatethePL/SQLstoredprocedureas:CREATEORREPLACEPROCEDUREmyproc(p1OUTSYS_REFCURSOR)ASBEGINOPENp1FORSELECT*FROMall_objectsWHEREROWNUM<;END;*/$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$e=oci_error();trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);}$stid=oci_parse($conn,'BEGINmyproc(:rc);END;');$refcur=oci_new_cursor($conn);oci_bind_by_name($stid,':rc',$refcur,-1,OCI_B_CURSOR);oci_execute($stid);//ExecutethereturnedREFCURSORandfetchfromitlikeastatementidentifieroci_execute($refcur);echo"<tableborder='1'>n";while(($row=oci_fetch_array($refcur,OCI_ASSOC+OCI_RETURN_NULLS))!=false){echo"<tr>n";foreach($rowas$item){echo"<td>".($item!==null?htmlentities($item,ENT_QUOTES):"&nbsp;")."</td>n";}echo"</tr>n";}echo"</table>n";oci_free_statement($refcur);oci_free_statement($stid);oci_close($conn);?>

Example # Pagination with oci_fetch_array() using a LIMIT-like query

<?php$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$e=oci_error();trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);}//Findtheversionofthedatabasepreg_match('/Release([0-9]+)./',oci_server_version($conn),$matches);$oracleversion=$matches[1];//Thisisthequeryyouwantto"page"through$sql='SELECTcity,postal_codeFROMlocationsORDERBYcity';if($oracleversion>=){//MakeuseofOraclecOFFSET/FETCHNEXTsyntax$sql=$sql.'OFFSET:offsetROWSFETCHNEXT:numrowsROWSONLY';}else{//OlderOracleversionsneedanestedqueryselectingasubset//from$sql.Or,iftheSQLstatementisknownatdevelopment//time,considerusingarow_number()functioninsteadofthis//nestedsolution.Inproductionenvironments,becarefulto//avoidSQLInjectionissueswithconcatenation.$sql="SELECT*FROM(SELECTa.*,ROWNUMASmy_rnumFROM($sql)aWHEREROWNUM<=:offset+:numrows)WHEREmy_rnum>:offset";}$offset=0;//skipthismanyrows$numrows=5;//return5rows$stid=oci_parse($conn,$sql);oci_bind_by_name($stid,':numrows',$numrows);oci_bind_by_name($stid,':offset',$offset);oci_execute($stid);while(($row=oci_fetch_array($stid,OCI_ASSOC+OCI_RETURN_NULLS))!=false){echo$row['CITY']."".$row['POSTAL_CODE']."<br>n";}//

Example # oci_fetch_array() with Oracle Database c Implicit Result Sets

<?php$conn=oci_connect('hr','welcome','localhost/pdborcl');if(!$conn){$e=oci_error();trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);}//RequiresOCI.0andOracleDatabasec//Alsoseeoci_get_implicit_resultset()$sql='DECLAREc1SYS_REFCURSOR;BEGINOPENc1FORSELECTcity,postal_codeFROMlocationsWHEREROWNUM<4ORDERBYcity;DBMS_SQL.RETURN_RESULT(c1);OPENc1FORSELECTcountry_idFROMlocationsWHEREROWNUM<4ORDERBYcity;DBMS_SQL.RETURN_RESULT(c1);END;';$stid=oci_parse($conn,$sql);oci_execute($stid);//Note:oci_fetch_allandoci_fetch()cannotbeusedinthismannerecho"<table>n";while(($row=oci_fetch_array($stid,OCI_ASSOC+OCI_RETURN_NULLS))!=false){echo"<tr>n";foreach($rowas$item){echo"<td>".($item!==null?htmlentities($item,ENT_QUOTES|ENT_SUBSTITUTE):"&nbsp;")."</td>n";}echo"</tr>n";}echo"</table>n";//

注释

Note:

Associative array indices need to be in uppercase for standard Oracle columns that were created with case insensitive names.

Note:

查询返回巨大数量的数据行时,通过增大oci8.default_prefetch值或使用 oci_set_prefetch() 可显著提高性能。

Note:

The function oci_fetch_array() is insignificantly slower than oci_fetch_assoc() or oci_fetch_row(), but is more flexible.

参见

oci_fetch() - Fetches the next row into result-buffer oci_fetch_all() - 获取结果数据的所有行到一个数组 oci_fetch_assoc() - Returns the next row from a query as an associative array oci_fetch_object() - Returns the next row from a query as an object oci_fetch_row() - Returns the next row from a query as a numeric array oci_set_prefetch() - 设置预提取行数

PHP:oci_field_name()的用法_Oracle函数 oci_field_name(PHP5,PECLOCI8=1.1.0)oci_field_name返回字段名说明stringoci_field_name(resource$statement,int$field)oci_field_name()返回与字段数字索引(从1开始)相对应的字段名

PHP:oci_field_is_null()的用法_Oracle函数 oci_field_is_null(PHP5,PECLOCI8=1.1.0)oci_field_is_null检查字段是否为NULL说明booloci_field_is_null(resource$statement,mixed$field)如果statement语句结果中返回的field字段的值是NU

PHP:oci_fetch_object()的用法_Oracle函数 oci_fetch_object(PHP5,PECLOCI8=1.1.0)oci_fetch_objectReturnsthenextrowfromaqueryasanobject说明objectoci_fetch_object(resource$statement)Returnsanobjectcontainingthenextresult-setrowofaquery.Eachattr

标签: PHP:oci_fetch_array()的用法_Oracle函数

本文链接地址:https://www.jiuchutong.com/biancheng/281107.html 转载请保留说明!

上一篇:PHP:oci_field_precision()的用法_Oracle函数

下一篇:PHP:oci_field_name()的用法_Oracle函数

  • 免抵税额计入什么科目
  • 外商投资企业要实缴资本么
  • 人民币报关可以吗
  • 办公家具发票要交税吗?
  • 定额发票收入怎么报税
  • 金蝶多核算项目怎么做
  • 政府土地收储是什么意思
  • 合伙制创投企业
  • 土地增值税申报流程
  • 增值税专用发票抵扣税额是什么意思
  • 临时聘用人员费用谁承担
  • 长期待摊费用做在什么记账凭证里
  • 长期股权投资如何审计
  • 金税三期啥意思
  • 地方教育附加费是什么意思
  • 所得税的费用限额怎么算
  • 环境工程开票多少税率
  • 办理核定企业所需资料
  • 新版edge浏览器兼容性视图怎么设置
  • 税款申报成功但没有缴款怎么办
  • 权益法下的相关税费计入
  • 资本公积主要包括哪些内容
  • 电脑总是死机
  • vue3.0组件库
  • 结转工程成本属于什么会计科目
  • mac补丁安装步骤
  • 政府性基金收入是政府非税收入吗
  • win10不关机设置方法
  • 专用发票怎样申报
  • 增值税发票没认证 可以重新开吗
  • Honeybee flying over crocuses in the Tatra Mountains, Poland (© Mirek Kijewski/Getty Images)
  • 小企业的费用包括生产成本吗
  • 科技推广和应用服务业属于第几产业
  • php获取post请求参数
  • 高新技术企业收入占比不到60%,能否享受税收优惠政策
  • 现代信号处理张贤达pdf
  • 前后端分离弊端
  • windowlocation用法
  • 自动驾驶讲解
  • 出口退税的会计科目一般记为什么
  • fio命令详解
  • 什么情况下要开外经证
  • 远期外汇合约的特点
  • 土地增值税成本费用
  • 房地产开发公司组织架构
  • phpcms作者名不显示怎么解决
  • 专利费用计入什么会计科目
  • 普通收据能入账嘛
  • 零税项目
  • 员工高铁票能抵扣吗
  • 个税的代扣代缴
  • 企业所得税期间费用明细表
  • 本年利润借方余额是什么意思呢
  • 库存商品毁损的会计分录
  • 固定资产增加
  • 运费与快递费的区别在哪
  • 小规模纳税人季报需要报什么
  • 个税汇算清缴什么意思?
  • 银行转账凭证可以保留多久
  • 偶然所得代扣代缴个人所得税会计分录
  • 没有发票意味着什么
  • 个人向公司借款怎么写
  • 结转本年利润按什么算
  • 付给供应商的货款怎么写记账凭证
  • 销项税现金流量附表如何指定
  • 无形资产计入待摊费用
  • 企业注销怎么回事
  • freebsd 配置ip
  • linux中字符设备有哪些
  • centos7.5设置静态ip
  • Win10预览版镜像
  • win10预览体验win11
  • perl随机数
  • bat查看ip地址和mac地址
  • javascript cookies
  • vs开发web教程
  • android 签名文件冲突
  • shell脚本监控进程
  • javascriptz
  • Unity3D游戏开发培训课程大纲
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设