Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 108,134

HOME > PHP Manual > oci_bind_by_name - Binds the PHP variable to the Oracle placeholder





ลองใช้ค้นหาข้อมูล


   
Bookmark.

oci_bind_by_name

(PHP 5, PECL oci8:1.1-1.2.4)

oci_bind_by_nameBinds the PHP variable to the Oracle placeholder

Description

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

Binds the PHP variable variable to the Oracle placeholder ph_name . Whether it will be used for input or output will be determined at run-time and the necessary storage space will be allocated.

Parameters

statement

An OCI statement.

ph_name

The placeholder.

variable

The PHP variable.

maxlength

Sets the maximum length for the bind. If you set it to -1, this function will use the current length of variable to set the maximum length.

type

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. The type parameter tells Oracle which descriptor is used. Default to SQLT_CHR. Possible values are:

  • SQLT_FILE - for BFILEs;

  • SQLT_CFILE - for CFILEs;

  • SQLT_CLOB - for CLOBs;

  • SQLT_BLOB - for BLOBs;

  • SQLT_RDD - for ROWIDs;

  • SQLT_NTY - for named datatypes;

  • SQLT_INT - for integers;

  • SQLT_CHR - for VARCHARs;

  • SQLT_BIN - for RAW columns;

  • SQLT_LNG - for LONG columns;

  • SQLT_LBI - for LONG RAW columns;

  • SQLT_RSET - for cursors, that were created before with oci_new_cursor().

Return Values

Returns TRUE on success or FALSE on failure.

Examples

Example #1 oci_bind_by_name() example

<?php
/* oci_bind_by_name example thies at thieso dot net (980221)
  inserts 3 records into emp, and uses the ROWID for updating the
  records just after the insert.
*/

$conn oci_connect("scott""tiger");

$stmt oci_parse($conn"
                          INSERT INTO
                                     emp (empno, ename)
                               VALUES
                                     (:empno,:ename)
                            RETURNING
                                     ROWID
                                 INTO
                                     :rid
                         "
);

$data = array(
              
1111 => "Larry",
              
2222 => "Bill",
              
3333 => "Jim"
             
);

$rowid oci_new_descriptor($connOCI_D_ROWID);

oci_bind_by_name($stmt":empno"$empno32);
oci_bind_by_name($stmt":ename"$ename32);
oci_bind_by_name($stmt":rid",   $rowid, -1OCI_B_ROWID);

$update oci_parse($conn"
                            UPDATE
                                  emp
                               SET
                                  sal = :sal
                             WHERE
                                  ROWID = :rid
                           "
);
oci_bind_by_name($update":rid"$rowid, -1OCI_B_ROWID);
oci_bind_by_name($update":sal"$sal,   32);

$sal 10000;

foreach (
$data as $empno => $ename) {
    
oci_execute($stmt);
    
oci_execute($update);
}

$rowid->free();

oci_free_statement($update);
oci_free_statement($stmt);

$stmt oci_parse($conn"
                          SELECT
                                *
                            FROM
                                emp
                           WHERE
                                empno
                              IN
                                (1111,2222,3333)
                         "
);
oci_execute($stmt);

while (
$row oci_fetch_assoc($stmt)) {
    
var_dump($row);
}

oci_free_statement($stmt);

/* delete our "junk" from the emp table.... */
$stmt oci_parse($conn"
                          DELETE FROM
                                     emp
                                WHERE
                                     empno
                                   IN
                                     (1111,2222,3333)
                         "
);
oci_execute($stmt);
oci_free_statement($stmt);

oci_close($conn);
?>

Remember, this function strips trailing whitespaces. See the following example:

Example #2 oci_bind_by_name() example

<?php
    $connection 
oci_connect('apelsin','kanistra');
    
$query "INSERT INTO test_table VALUES(:id, :text)";

    
$statement oci_parse($query);
    
oci_bind_by_name($statement":id"1);
    
oci_bind_by_name($statement":text""trailing spaces follow     ");
    
oci_execute($statement);
    
/*
     This code will insert into DB string 'trailing spaces follow', without
     trailing spaces
    */
?>

Example #3 oci_bind_by_name() example

<?php
    $connection 
oci_connect('apelsin','kanistra');
    
$query "INSERT INTO test_table VALUES(:id, 'trailing spaces follow      ')";

    
$statement oci_parse($query);
    
oci_bind_by_name($statement":id"1);
    
oci_execute($statement);
    
/*
     And this code will add 'trailing spaces follow      ', preserving
     trailing whitespaces
    */
?>

Return Values

Returns TRUE on success or FALSE on failure.

Notes

Warning

Do not use magic_quotes_gpc or addslashes() and oci_bind_by_name() simultaneously as no quoting is needed and any magically applied quotes will be written into your database as oci_bind_by_name() is not able to distinguish magically added quotings from those added intentionally.

Note: In PHP versions before 5.0.0 you must use ocibindbyname() instead. This name still can be used, it was left as alias of oci_bind_by_name() for downwards compatability. This, however, is deprecated and not recommended.



ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


สุดยอด Source Code V2.0
 

แจ้งชำระเงิน/โอนเงิน
 

Hit Link
   







Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2020 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 , 08-9968-0655 อัตราราคา คลิกที่นี่