位置: 编程技术 - 正文

PHP:oci_bind_by_name()的用法_Oracle函数

编辑:rootadmin
oci_bind_by_name

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

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

(PHP 5, PECL OCI8 >= 1.1.0)

oci_bind_by_name — 绑定一个 PHP 变量到一个 Oracle 位置标志符

说明 bool oci_bind_by_name ( resource $stmt , string $ph_name , mixed &$variable [, int $maxlength [, int $type ]] )

oci_bind_by_name() 将 PHP 变量 variable 绑定到 Oracle 的位置标志符 ph_name。该变量是否会被用作输入输出是在运行时决定的,并且函数给该变量分配必要的存储空间。length 参数确定该绑定的最大长度,如果将 length 设为 -1,oci_bind_by_name() 会用 variable 变量的当前长度确定绑定的最大长度。

如果要绑定一个抽象数据类型(LOB/ROWID/BFILE),需要先用 oci_new_descriptor() 函数分配空间。length 没有用于抽象数据类型,应被设为 -1。type 参数告诉 Oracle 要使用什么样的描述符。可能的值为:

SQLT_FILE - 对应于 BFILE;

SQLT_CFILE - 对应于 CFILE;

SQLT_CLOB - 对应于 CLOB;

SQLT_BLOB - 对应于 BLOB;

SQLT_ROWID - 对应于 ROWID;

SQLT_NTY - 对应于有名字的数据类型;

SQLT_INT - 对应于 integers;

SQLT_CHR - 对应于 VARCHARs;

SQLT_BIN - 对应于 RAW 列;

SQLT_LNG - 对应于 LONG 列;

SQLT_LBI - 对应于 LONG RAW 列;

SQLT_RSET - 对应于游标,是之前由 oci_new_cursor() 创建的。

Example #1 oci_bind_by_name() 例子

<?php/*oci_bind_by_nameexamplethiesatthiesodotnet()inserts3recordsintoemp,andusestheROWIDforupdatingtherecordsjustaftertheinsert.*/$conn=oci_connect("scott","tiger");$stmt=oci_parse($conn,"INSERTINTOemp(empno,ename)VALUES(:empno,:ename)RETURNINGROWIDINTO:rid");$data=array(=>"Larry",=>"Bill",=>"Jim");$rowid=oci_new_descriptor($conn,OCI_D_ROWID);oci_bind_by_name($stmt,":empno",$empno,);oci_bind_by_name($stmt,":ename",$ename,);oci_bind_by_name($stmt,":rid",$rowid,-1,OCI_B_ROWID);$update=oci_parse($conn,"UPDATEempSETsal=:salWHEREROWID=:rid");oci_bind_by_name($update,":rid",$rowid,-1,OCI_B_ROWID);oci_bind_by_name($update,":sal",$sal,);$sal=;foreach($dataas$empno=>$ename){oci_execute($stmt);oci_execute($update);}$rowid->free();oci_free_statement($update);oci_free_statement($stmt);$stmt=oci_parse($conn,"SELECT*FROMempWHEREempnoIN(,,)");oci_execute($stmt);while($row=oci_fetch_assoc($stmt)){var_dump($row);}oci_free_statement($stmt);/*deleteour"junk"fromtheemptable....*/$stmt=oci_parse($conn,"DELETEFROMempWHEREempnoIN(,,)");oci_execute($stmt);oci_free_statement($stmt);oci_close($conn);?>

记住,本函数删除了行尾的空白字符。见以下例子:

Example #2 oci_bind_by_name() 例子

<?php$connection=oci_connect('apelsin','kanistra');$query="INSERTINTOtest_tableVALUES(:id,:text)";$statement=oci_parse($query);oci_bind_by_name($statement,":id",1);oci_bind_by_name($statement,":text","trailingspacesfollow");oci_execute($statement);/*ThiscodewillinsertintoDBstring'trailingspacesfollow',withouttrailingspaces*/?>

Example #3 oci_bind_by_name() 例子

<?php$connection=oci_connect('apelsin','kanistra');$query="INSERTINTOtest_tableVALUES(:id,'trailingspacesfollow')";$statement=oci_parse($query);oci_bind_by_name($statement,":id",1);oci_execute($statement);/*Andthiscodewilladd'trailingspacesfollow',preservingtrailingwhitespaces*/?>

Warning

不要将 magic_quotes_gpc 或 addslashes() 与 oci_bind_by_name() 同时使用,因为不需要转义,任何自动加上的引号都会被写入数据库中,因为 oci_bind_by_name() 不能分辨有意加上的引号和魔术引号。

成功时返回 TRUE, 或者在失败时返回 FALSE。

Note:

在 PHP 5.0.0 之前的版本必须使用 ocibindbyname() 替代本函数。该函数名仍然可用,为向下兼容作为 oci_bind_by_name() 的别名。不过其已被废弃,不推荐使用。

参数

statement

A valid OCI8 statement identifer.

bv_name

The colon-prefixed bind variable placeholder used in the statement. The colon is optional in bv_name. Oracle does not use question marks for placeholders.

variable

The PHP variable to be associated with bv_name

maxlength

Sets the maximum length for the data. If you set it to -1, this function will use the current length of variable to set the maximum length. In this case the variable must exist and contain data when oci_bind_by_name() is called.

type

The datatype that Oracle will treat the data as. The default type used is SQLT_CHR. Oracle will convert the data between this type and the database column (or PL/SQL variable type), when possible.

If you need to bind an abstract datatype (LOB/ROWID/BFILE) you need to allocate it first using the oci_new_descriptor() function. The length is not used for abstract datatypes and should be set to -1.

Possible values for type are:

SQLT_BFILEE or OCI_B_BFILE - for BFILEs;

SQLT_CFILEE or OCI_B_CFILEE - for CFILEs;

SQLT_CLOB or OCI_B_CLOB - for CLOBs;

SQLT_BLOB or OCI_B_BLOB - for BLOBs;

SQLT_RDD or OCI_B_ROWID - for ROWIDs;

SQLT_NTY or OCI_B_NTY - for named datatypes;

PHP:oci_bind_by_name()的用法_Oracle函数

SQLT_INT or OCI_B_INT - for integers;

SQLT_CHR - for VARCHARs;

SQLT_BIN or OCI_B_BIN - for RAW columns;

SQLT_LNG - for LONG columns;

SQLT_LBI - for LONG RAW columns;

SQLT_RSET - for cursors created with oci_new_cursor().

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE。

范例

Example #4 Inserting data with oci_bind_by_name()

<?php//

Example #5 Binding once for multiple executions

<?php//

Example #6 Binding with a foreach() loop

<?php$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$m=oci_error();trigger_error(htmlentities($m['message']),E_USER_ERROR);}$sql='SELECT*FROMdepartmentsWHEREdepartment_name=:dnameANDlocation_id=:loc';$stid=oci_parse($conn,$sql);$ba=array(':dname'=>'ITSupport',':loc'=>);foreach($baas$key=>$val){//oci_bind_by_name($stid,$key,$val)doesnotwork//becauseitbindseachplaceholdertothesamelocation:$val//insteadusetheactuallocationofthedata:$ba[$key]oci_bind_by_name($stid,$key,$ba[$key]);}oci_execute($stid);$row=oci_fetch_array($stid,OCI_ASSOC+OCI_RETURN_NULLS);foreach($rowas$item){print$item."<br>n";}oci_free_statement($stid);oci_close($conn);?>

Example #7 Binding in a WHERE clause

<?php$conn=oci_connect("hr","hrpwd","localhost/XE");if(!$conn){$m=oci_error();trigger_error(htmlentities($m['message']),E_USER_ERROR);}$sql='SELECTlast_nameFROMemployeesWHEREemployee_id=:eidbv';$stid=oci_parse($conn,$sql);$myeid=;oci_bind_by_name($stid,':eidbv',$myeid);oci_execute($stid);$row=oci_fetch_array($stid,OCI_ASSOC);echo$row['LAST_NAME']."<br>n";//Outputis//Kochharoci_free_statement($stid);oci_close($conn);?>

Example #8 Binding with a LIKE clause

<?php$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$m=oci_error();trigger_error(htmlentities($m['message']),E_USER_ERROR);}//Findallcitiesthatbeginwith'South'$stid=oci_parse($conn,"SELECTcityFROMlocationsWHEREcityLIKE:bv");$city='South%';//'%'isawildcardinSQLoci_bind_by_name($stid,":bv",$city);oci_execute($stid);oci_fetch_all($stid,$res);foreach($res['CITY']as$c){print$c."<br>n";}//Outputis//SouthBrunswick//SouthSanFrancisco//Southlakeoci_free_statement($stid);oci_close($conn);?>

Example #9 Binding with REGEXP_LIKE

<?php$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$m=oci_error();trigger_error(htmlentities($m['message']),E_USER_ERROR);}//Findallcitiesthatcontain'ing'$stid=oci_parse($conn,"SELECTcityFROMlocationsWHEREREGEXP_LIKE(city,:bv)");$city='.*ing.*';oci_bind_by_name($stid,":bv",$city);oci_execute($stid);oci_fetch_all($stid,$res);foreach($res['CITY']as$c){print$c."<br>n";}//Outputis//Beijing//Singaporeoci_free_statement($stid);oci_close($conn);?>

For a small, fixed number of IN clause conditions, use individual bind variables. Values unknown at run time can be set to NULL. This allows a single statement to be used by all application users, maximizing Oracle DB cache efficiency.

Example # Binding Multiple Values in an IN Clause

<?php$conn=oci_connect('hr','welcome','localhost/XE');if(!$conn){$m=oci_error();trigger_error(htmlentities($m['message']),E_USER_ERROR);}$sql='SELECTlast_nameFROMemployeesWHEREemployee_idin(:e1,:e2,:e3)';$stid=oci_parse($conn,$sql);$mye1=;$mye2=;$mye3=NULL;//pretendwewerenotgiventhisvalueoci_bind_by_name($stid,':e1',$mye1);oci_bind_by_name($stid,':e2',$mye2);oci_bind_by_name($stid,':e3',$mye3);oci_execute($stid);oci_fetch_all($stid,$res);foreach($res['LAST_NAME']as$name){print$name."<br>n";}//Outputis//Ernst//Hunoldoci_free_statement($stid);oci_close($conn);?>

Example # Binding a ROWID returned by a query

<?php//

Example # Binding a ROWID on INSERT

<?php//Thisexampleinsertsanid&name,andthenupdatesthesalary//

Example # Binding for a PL/SQL stored function

<?php//BeforerunningthePHPprogram,createastoredfunctionin//SQL*

Example # Binding parameters for a PL/SQL stored procedure

<?php//BeforerunningthePHPprogram,createastoredprocedurein//SQL*

Example # Binding a CLOB column

<?php//Beforerunning,

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE。

注释 Warning

Do not use magic_quotes_gpc or addslashes() and oci_bind_by_name() simultaneously as no quoting is needed. Any magically applied quotes will be written into your database because oci_bind_by_name() inserts data verbatim and does not remove quotes or escape characters.

Note:

If you bind a string to a CHAR column in a WHERE clause, remember that Oracle uses blank-padded comparison semantics for CHAR columns. Your PHP variable should be blank padded to the same width as the column for the WHERE clause to succeed.

Note:

The PHP variable argument is a reference. Some forms of loops do not work as expected:

<?phpforeach($myarrayas$key=>$value){oci_bind_by_name($stid,$key,$value);}?>

This binds each key to the location of $value, so all bound variables end up pointing to the last loop iteration&#;s value. Instead use the following:

<?phpforeach($myarrayas$key=>$value){oci_bind_by_name($stid,$key,$myarray[$key]);}?>

Note:

In PHP versions before 5.0.0 you must use ocibindbyname() instead. 在当前版本中,旧的函数名还可以被使用,但已经被废弃并不建议使用。

参见

oci_bind_array_by_name() - Binds a PHP array to an Oracle PL/SQL array parameter oci_parse() - 配置 Oracle 语句预备执行

PHP:oci_define_by_name()的用法_Oracle函数 oci_define_by_name(PHP5,PECLOCI8=1.1.0)oci_define_by_name在SELECT中使用PHP变量作为定义的步骤说明booloci_define_by_name(resource$statement,string$column_name,mixed&$variable[,int$type])o

PHP:oci_client_version()的用法_Oracle函数 oci_client_version(PHP5.3.7,PECLOCI8=1.4.6)oci_client_versionReturnstheOracleclientlibraryversion说明stringoci_client_version(void)ReturnsastringcontainingtheversionnumberoftheOracleCclientlibraryth

PHP:oci_cancel()的用法_Oracle函数 oci_cancel(PHP5,PECLOCI8=1.1.0)oci_cancel中断游标读取数据说明booloci_cancel(resource$statement)oci_cancel()使一个游标无效,释放所有与之关联的资源并取消了从中读取

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

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

上一篇:PHP:oci_error()的用法_Oracle函数(php or)

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

  • 房地产企业税率为5销售水泥怎么算
  • 等线补交以前年度附加税会计分录
  • 应付账款坏账了怎么处理
  • 本期缴纳上期应纳税额是自动生成的吗?
  • 可供出售金融资产和交易性金融资产
  • 承兑贴现给个人怎么做账
  • 出租车公司给车都上什么保险
  • 税务顾问费怎么做账务处理?
  • 城建税和教育费附加的计税依据是什么
  • 个人给单位干的小工程需代扣个税吗?
  • 税控盘减免在哪里填报
  • 加计扣除两种情况
  • 滞纳金由财务人员承担
  • 其他货币资金包括存出保证金吗
  • 过路费可以抵税吗
  • 购买材料再进在建工程的账务处理
  • 新公司税控盘购买流程
  • 公司购进的商品自己用的,税金怎么走账
  • 应交税费核算
  • 投资合伙企业对公司有债务责任吗
  • 应付职工薪酬年末需要结转吗
  • 农业公司收到项目资金
  • 出口退税的会计分录实例
  • php封装api
  • 代收代付的垃圾清运费没发票能入账吗
  • 高新企业研发支出转产成品
  • 应付票据到期怎么处理
  • 错误申报多交增值税已经扣税
  • 向银行借入长期借款50万元
  • 公司一直没有收入怎么办
  • 带息应收票据应于收到或开出或承兑时
  • 季度所得税表中营业收入填万元还是总金额
  • 合伙企业利润分配原则
  • 专票如何申领
  • php取mysql查询单条数据
  • 怎么调试vue项目
  • 万能的python
  • php曲线图模板
  • cancel怎么关
  • 社会团体收取的会费是否缴纳企业所得税
  • 预扣预缴申报未缴税款
  • 小规模纳税人如何开专票
  • 开启php
  • 应付职工薪酬住房公积金怎么算
  • MySQL中Nested-Loop Join算法小结
  • python中Plotly Express是什么?
  • 定期定额征收税款
  • 微信小程序 滚动 变色
  • 长期股权投资与其他权益工具投资的区别
  • 困难企业社保费返还
  • 融资租赁固定资产折旧年限
  • 长期股权投资转让会计处理
  • 员工房屋租赁合同
  • 长期借款计提利息会计分录怎么做
  • 为什么生产经营许可证要第三方代办
  • 实际开票金额比外经证金额大
  • 员工宿舍的物业费可以抵扣进项税吗
  • 餐饮开票税率
  • 票据包括哪些
  • 企业失信是什么意思
  • 建账怎么建
  • sp_executesql 使用复杂的Unicode 表达式错误的解决方法
  • mysql详细教程
  • win8设置怎么打开
  • 优盘安装系统
  • win10系统更新后
  • centos6.5忘记密码
  • win7系统点击计算机图标未响应
  • Windows 7 Apache下计算机无法访问局域网网站的解决方法
  • 原生js添加css样式
  • 还原分区和引导分区
  • cs1-u和cs1-f的区别
  • c# hashtable 用法
  • 每天一篇文章锻炼口才的文章
  • 浅谈Jquery中Ajax异步请求中的async参数的作用
  • 国家税务局查验发票显示网络异常
  • 2023浙江高考首考状元
  • 个人所得税网上报税流程
  • 海南购房税费最新2019规定
  • 苏州虎丘区税务局在哪里
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设