位置: 编程技术 - 正文

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

  • 城镇土地使用税暂行条例
  • 工商年报的纳税总额是什么
  • 结转未交增值税会计科目怎么写
  • 拿工资要开发票,发票去哪儿开?
  • 当月开的票必须当月交税吗
  • 财务报表怎么重新做
  • 土地增值税清算是什么意思
  • 融资租入的办公楼属于固定资产吗
  • 商场采用联营方式的原因
  • 电子承兑汇票接收和转出步骤
  • 投资性房地产计量模式的转换
  • 怎么查找地方教育附加税的计税依据?
  • 3月申报的是什么时候的个税
  • 当期可抵扣进项税额包括进项转出额吗
  • 职工福利费支出计入什么科目
  • 开通分期付款
  • 向境外企业支付技术咨询指导费
  • 两家公司合租一个房子
  • 处置报废车辆如何缴纳增值税
  • windows11我的电脑怎么放到桌面
  • 试生产时间规定
  • 股份公司和有限公司工作哪个好一些
  • 笔记本电脑bios设置
  • centos7安装php7.3
  • php字符串定义的三种方式
  • 出口货物退税率为0,是否出口免税
  • 销售商品收到商业汇票一张该笔业务应编制的记账凭证是
  • 职工医疗保险补交6万与交居民每交300哪个合算?
  • 企业会计核算利润表
  • php自动执行函数
  • 发行的企业债券是什么会计科目
  • phpstorm配置php环境 mac os
  • 初学者是啥意思
  • 关于php通用返回的问题
  • php获取并显示用户的用户名
  • php redis数据类型
  • 工会经费计税依据是上年工资还是当年工资
  • react+
  • 企业会计准则季度怎么填
  • 营改增前取得的有形动产为标的物
  • 不同会计制度资产负债表金额不一样
  • 一个人失恋了该怎么安慰她
  • 一般纳税人开普票税率是多少
  • mysql文件更改存放路径
  • 民间非营利组织财务管理制度
  • 企业会计人员审计程序
  • 小规模免征增值税到什么时间止
  • 建设单位支付给施工单位的民工工资
  • 委托代销商品的核算
  • 租入的厂房
  • 个税起征点调整最新消息
  • 委托加工业务的财务职责
  • 我国流转税有哪些
  • 收到损坏物品赔偿金如何入账
  • 损益类所得税费用
  • 股东是否实缴出资的举证责任
  • 工会经费返还属于什么收入
  • 汇率的差额如何处理
  • 出口货物没有进项发票用什么平台申报
  • sql中where语句的写法
  • 数据库连接说明
  • mysql 正则表达式分组替换
  • fedora29
  • system idle process 连接了外网
  • linux计划任务不生效
  • windows开发是什么
  • win8进入电脑休眠后怎么唤醒
  • win10预览版绿屏重启解决
  • win7用户在哪
  • windows8的ie浏览器在哪
  • node.js操作文件
  • javascript面向对象编程指南
  • 深入理解新发展理念,推进供给侧结构性改革
  • bootstrap怎么学
  • javascript definitive guide
  • python struct库
  • jquery监听span内容的变化
  • python怎么用数组
  • 广州市税务局长
  • 汽车燃油税每年要交吗
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设