Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

The ocibindbyname function binds an Oracle placeholder to a PHP variable. You must
supply a valid statement identifier as created by ociparse, the name of the placeholder, a
reference to a PHP variable, and the maximum length of the bind data. You may use a
value of -1 to use the length of the variable passed as the variable argument.


The optional type argument specifies a data type and is necessary if you wish to bind to
an abstract data type. Use one of the following constants to set the data type:
OCI_B_BLOB, OCI_B_CFILE, OCI_B_CLOB, OCI_B_FILE, OCI_B_ROWID. Make sure you
use ocinewdescriptor before binding to an abstract data type. You also need to use -1
for the length argument.


<?
//set-up data to insert
$NewEmployee = array(
array(8001, 'Smith', 'Clerk'),
array(8002, 'Jones', 'Analyst'),
array(8003, 'Atkinson', 'President')
);


//connect to database
$Connection = ocilogon("scott", "tiger");


//assemble query
$Query = "INSERT INTO emp (EMPNO, ENAME, JOB, HIREDATE) ";
$Query .= "VALUES (:empno, :ename, :job, SYSDATE ) ";
$Query .= "RETURNING ROWID INTO :rowid ";


//parse query
$Statement = ociparse($Connection, $Query);


//create descriptor the abstract data type
$RowID = ocinewdescriptor($Connection, OCI_D_ROWID);


//bind input and output variables
ocibindbyname($Statement, ":empno", &$EmployeeNumber, 32);
ocibindbyname($Statement, ":ename", &$EmployeeName, 32);
ocibindbyname($Statement, ":job", &$Job, 32);
ocibindbyname($Statement, ":rowid", &$RowID, -1, OCI_B_ROWID);


//loop over each new employee
while(list($key, $EmployeeInfo) = each($NewEmployee))
{
list($EmployeeNumber, $EmployeeName, $Job) =
$EmployeeInfo;


//execute query, do not automatically commit
ociexecute($Statement, OCI_DEFAULT);


print("$EmployeeNumber has ROWID $RowID
\n");
}


//free the statement
ocifreestatement($Statement);

Free download pdf