位置: 编程技术 - 正文

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函数

  • 企业所得税汇算清缴
  • 开发票,对方收取税点,如何计算
  • 微信支付宝收入计入科目
  • 残疾人保障金做什么会计科目
  • 非同一控制下企业合并对价小于可辨认
  • 长期股权投资的初始投资成本
  • 出口货物的销售额怎么算
  • 个人债务转成股份
  • 有限合伙企业清算
  • 失控发票进项税额转出申报表填写
  • 代扣代缴个人所得税现金流计入哪里
  • 装修发票是什么发票
  • 企业财务月确定不当造成税务问题
  • 小规模纳税人废品站卖废品发票开什么项目
  • 银行中间业务能开具增值税专票吗
  • 自建厂房领用材料进项税的处理
  • 广告公司返点是什么意思
  • 公司名下商品房卖给个人后房产税怎么交
  • 在线上网测试
  • windos11安卓
  • 商品房买卖合同备案查询
  • mac截图如何保存到照片
  • php数组函数输出《咏雪》里有多少"片"字
  • 物业管理费发票图片
  • visual studio code 调试php方法(图文详解)
  • 行政事业单位资产负债表
  • 安装windows(install windows)
  • php 集成环境
  • js鼠标事件包括哪几种
  • 建设项目罚款支出的会计处理
  • php使用函数限制字符串长度和格式
  • 推荐 4个有趣实践作业
  • jquery获取值的几种方法
  • dedecms51
  • python中import语句
  • 投稿网址打不开
  • mysql怎么截取字段
  • mongodb启动命令 linux
  • mongodb createindex
  • mongodb导入
  • 长期待摊费用的摊销期限应该是
  • 公司吸收合并是利好吗
  • 企业所得税应按季预缴,年末汇算清缴
  • 固定资产计入管理费用就不用折旧了吗
  • 可供出售金融资产属于什么科目
  • 股权并购与收购的区别
  • 已计提完的固定资产怎么做账
  • 财政补助资金不需要政府采购
  • 抵债资产如何做债权转让
  • 办公室用茶叶怎么入账
  • 免抵税额下个月还能退吗
  • 固定资产计提完折旧残值怎么处理
  • 无息的银行承兑汇票
  • 工会活动支出如何记账
  • 主营业务收入少计跨年调整
  • 如何跨数据库查询
  • 一条sql语句搞定一个数据
  • 主板如何清除cmos
  • w10预览版新功能
  • ubuntu更换版本
  • unix系统的文件分为哪三种存取结构
  • u启动怎么装机
  • 笔记本没有光驱怎么加装固态硬盘
  • windows 隐藏软件
  • sointgr.exe - sointgr是什么进程 有什么用
  • linux配置光纤
  • ExtJS4中的requires使用方法示例介绍
  • Linux删除大量文件
  • linux timeline
  • 如何使用css设置元素的层叠效果?
  • linux脚本自启
  • shell 比较大小
  • javascript学习指南
  • 河南省电子税务局官网入口
  • 四川省一般纳税人资格证明
  • 银川到大武口的汽车站时刻表
  • 会议服务的服务定位是什么
  • 珠宝消费税怎么申报
  • 个人利息收入属于什么收入
  • 税务总局四个确保
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设