From 064da69a6fc251aded9463eff37100ac9fe9a3e5 Mon Sep 17 00:00:00 2001 From: Mark Britton Date: Wed, 7 Jul 1999 20:08:13 +0000 Subject: [PATCH] Added documentation for most of the OCI functions. Still have a few more to add. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@10415 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/oci8.sgml | 635 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 606 insertions(+), 29 deletions(-) diff --git a/functions/oci8.sgml b/functions/oci8.sgml index bc390b7f15..3d3b0ffc76 100644 --- a/functions/oci8.sgml +++ b/functions/oci8.sgml @@ -15,29 +15,33 @@ @@ -287,25 +291,138 @@ OCILogoff($conn); - + - OCINumRows - Gets the number of affectend rows + OCINewDescriptor + Initialize a new empty descriptor LOB/FILE (LOB is default) Description - int OCINumRows + string OCINewDescriptor + int connection + int type + + + OCINewDescriptor Allocates storage to hold descriptors or LOB locators. + Valid values for the valid type are OCI_D_FILE, OCI_D_LOB, OCI_D_ROWID. + + + + OCINewDescriptor + +<?php + /* This script is designed to be called from a HTML form. + * It expects $user, $password, $table, $where, and $commitsize + * to be passed in from the form. The script then deletes + * the selected rows using the ROWID and commits after each + * set of $commitsize rows. (Use with care, there is no rollback) + */ + $conn = OCILogon($user, $password); + $stmt = OCIParse($conn,"select rowid from $table $where"); + $rowid = OCINewDescriptor($conn,OCI_D_ROWID); + OCIDefineByName($stmt,"ROWID",&$rowid); + OCIExecute($stmt); + while ( OCIFetch($stmt) ) { + $nrows = OCIRowCount($stmt); + $delete = OCIParse($conn,"delete from $table where ROWID = :rid"); + OCIBindByName($delete,":rid",&$rowid,-1,OCI_B_ROWID); + OCIExecute($delete); + print "$nrows\n"; + if ( ($nrows % $commitsize) == 0 ) { + OCICommit($conn); + } + } + $nrows = OCIRowCount($stmt); + print "$nrows deleted...\n"; + OCIFreeStatement($stmt); + OCILogoff($conn); +?> + + + + + + + OCIRowCount + Gets the number of affected rows + + + Description + + int OCIRowCount int statement - OCINumRows returns the number of rows affected + OCIRowCounts returns the number of rows affected for eg update-statements. This funtions will not tell you the number of rows that a select will return! - + + + OCIRowCount + +<?php + print "<HTML><PRE>"; + $conn = OCILogon("scott","tiger"); + $stmt = OCIParse($conn,"create table emp2 as select * from emp"); + OCIExecute($stmt); + print OCIRowCount($stmt) . " rows inserted.<BR>"; + OCIFreeStatement($stmt); + $stmt = OCIParse($conn,"delete from emp2"); + OCIExecute($stmt); + print OCIRowCount($stmt) . " rows deleted.<BR>"; + OCICommit($conn); + OCIFreeStatement($stmt); + $stmt = OCIParse($conn,"drop table emp2"); + OCIExecute($stmt); + OCIFreeStatement($stmt); + OCILogOff($conn); + print "</PRE></HTML>"; +?> + + + + OCINumCols + Return the number of result columns in a statement + + + Description + + int OCINumCols + int stmt + + + OCINumCols returns the number of columns in a statement + + OCINumCols + +<?php + print "<HTML><PRE>\n"; + $conn = OCILogon("scott", "tiger"); + $stmt = OCIParse($conn,"select * from emp"); + OCIExecute($stmt); + while ( OCIFetch($stmt) ) { + print "\n"; + $ncols = OCINumCols($stmt); + for ( $i = 1; $i <= $ncols; $i++ ) { + $column_name = OCIColumnName($stmt,$i); + $column_value = OCIResult($stmt,$i); + print $column_name . ': ' . $column_value . "\n"; + } + print "\n"; + } + OCIFreeStatement($stmt); + OCILogoff($conn); + print "</PRE>"; + print "</HTML>\n"; +?> + + + + OCIResult @@ -383,6 +500,66 @@ OCILogoff($conn); + + + OCIFetchStatement + Fetch all rows of result data into an array. + + + Description + + int OCIFetchStatement + int stmt + array &variable + + + OCIFetchStatement fetches all the rows from a + result into a user-defined array. OCIFetchStatement + returns the number of rows fetched. + + + OCIFetchStatement + +<?php +/* OCIFetchStatement example mbritton@verinet.com (990624) */ + +$conn = OCILogon("scott","tiger"); + +$stmt = OCIParse($conn,"select * from emp"); + +OCIExecute($stmt); + +$nrows = OCIFetchStatement($stmt,$results); +if ( $nrows > 0 ) { + print "<TABLE BORDER=\"1\">\n"; + print "<TR>\n"; + while ( list( $key, $val ) = each( $results ) ) { + print "<TH>$key</TH>\n"; + } + print "</TR>\n"; + + for ( $i = 0; $i < $nrows; $i++ ) { + reset($results); + print "<TR>\n"; + while ( $column = each($results) ) { + $data = $column['value']; + print "<TD>$data[$i]</TD>\n"; + } + print "</TR>\n"; + } + print "</TABLE>\n"; +} else { + echo "No data found<BR>\n"; +} +print "$nrows Records Selected<BR>\n"; + +OCIFreeStatement($stmt); +OCILogoff($conn); + +?> + + + OCIColumnIsNULL @@ -424,9 +601,409 @@ OCILogoff($conn); the column-number (1-Based) or the column-name for the col parameter. + + + OCIColumnSize + +<?php + print "<HTML><PRE>\n"; + $conn = OCILogon("scott", "tiger"); + $stmt = OCIParse($conn,"select * from emp"); + OCIExecute($stmt); + print "<TABLE BORDER=\"1\">"; + print "<TR>"; + print "<TH>Name</TH>"; + print "<TH>Type</TH>"; + print "<TH>Length</TH>"; + print "</TR>"; + $ncols = OCINumCols($stmt); + for ( $i = 1; $i <= $ncols; $i++ ) { + $column_name = OCIColumnName($stmt,$i); + $column_type = OCIColumnType($stmt,$i); + $column_size = OCIColumnSize($stmt,$i); + print "<TR>"; + print "<TD>$column_name</TD>"; + print "<TD>$column_type</TD>"; + print "<TD>$column_size</TD>"; + print "</TR>"; + } + OCIFreeStatement($stmt); + OCILogoff($conn); + print "</PRE>"; + print "</HTML>\n"; +?> + + See also OCINumCols, OCIColumnName, + and OCIColumnSize. + + + OCIServerVersion + Return a string containing server version information. + + + Description + + string OCIServerVersion + int conn + + + + OCIServerVersion + +<?php + $conn = OCILogon("scott","tiger"); + print "Server Version: " . OCIServerVersion($conn); + OCILogOff($conn); +?> + + + + + + + OCIStatementType + Return the type of an OCI statement. + + + Description + + string OCIStatementType + int stmt + + + OCIStatementType returns on of the following values: + + "SELECT" + "UPDATE" + "DELETE" + "INSERT" + "CREATE" + "DROP" + "ALTER" + "BEGIN" + "DECLARE" + "UNKNOWN" + + + + Code examples + +<?php + print "<HTML><PRE>"; + $conn = OCILogon("scott","tiger"); + $sql = "delete from emp where deptno = 10"; + + $stmt = OCIParse($conn,$sql); + if ( OCIStatementType($stmt) == "DELETE" ) { + die "You are not allowed to delete from this table<BR>"; + } + + OCILogoff($conn); + print "</PRE></HTML>"; +?> + + + + + + + + OCINewCursor + return a new cursor (Statement-Handle) - use this to bind ref-cursors! + + + Description + + int OCINewCursor + int conn + + + OCINewCursor allocates a new statement handle on the specified + connection. + + + + Using a REF CURSOR from a stored procedure + +<?php +// suppose your stored procedure info.output returns a ref cursor in :data + +$conn = OCILogon("scott","tiger"); +$curs = OCINewCursor($conn); +$stmt = OCIParse($conn,"begin info.output(:data); end;"); + +ocibindbyname($stmt,"data",&$curs,-1,OCI_B_CURSOR); +ociexecute($stmt); +ociexecute($curs); + +while (OCIFetchInto($curs,&$data)) { + var_dump($data); +} + +OCIFreeCursor($stmt); +OCIFreeStatement($curs); +OCILogoff($conn); +?> + + + + Using a REF CURSOR in a select statement + +<?php +print "<HTML><BODY>"; +$conn = OCILogon("scott","tiger"); +$count_cursor = "CURSOR(select count(empno) num_emps from emp " . + "where emp.deptno = dept.deptno) as EMPCNT from dept"; +$stmt = OCIParse($conn,"select deptno,dname,$count_cursor"); + +ociexecute($stmt); +print "<TABLE BORDER=\"1\">"; +print "<TR>"; +print "<TH>DEPT NAME</TH>"; +print "<TH>DEPT #</TH>"; +print "<TH># EMPLOYEES</TH>"; +print "</TR>"; + +while (OCIFetchInto($stmt,&$data,OCI_ASSOC)) { + print "<TR>"; + $dname = $data["DNAME"]; + $deptno = $data["DEPTNO"]; + print "<TD>$dname</TD>"; + print "<TD>$deptno</TD>"; + ociexecute($data[ "EMPCNT" ]); + while (OCIFetchInto($data[ "EMPCNT" ],&$subdata,OCI_ASSOC)) { + $num_emps = $subdata["NUM_EMPS"]; + print "<TD>$num_emps</TD>"; + } + print "</TR>"; +} +print "</TABLE>"; +print "</BODY></HTML>"; +OCIFreeStatement($stmt); +OCILogoff($conn); +?> + + + + + + + OCIFreeStatement + Free all resources associated with a statement. + + + Description + + int OCIFreeStatement + int stmt + + + OCIFreeStatement returns true if successful, or false if + unsuccessful. + + + + + + + OCIFreeCursor + Free all resources associated with a cursor. + + + Description + + int OCIFreeCursor + int stmt + + + OCIFreeCursor returns true if successful, or false if + unsuccessful. + + + + + + + OCIPLogon + Connect to an Oracle database and log on using a persistant connection. + Returns a new session. + + + Description + + int OCIPLogon + int conn + + + OCIPLogin Creates a persistent connection to an Oracle 8 database + and logs on. If the optional third parameter is not specified, PHP uses the environment + variable ORACLE_SID to determine which database to connect to. + + + + + + OCIColumnName + Returns the name of a column. + + + Description + + string OCIColumnName + int stmt + int col + + + OCIColumnName returns the name of the column + corresponding to the column number (1-based) that is passed in. + + + + OCIColumnName + +<?php + print "<HTML><PRE>\n"; + $conn = OCILogon("scott", "tiger"); + $stmt = OCIParse($conn,"select * from emp"); + OCIExecute($stmt); + print "<TABLE BORDER=\"1\">"; + print "<TR>"; + print "<TH>Name</TH>"; + print "<TH>Type</TH>"; + print "<TH>Length</TH>"; + print "</TR>"; + $ncols = OCINumCols($stmt); + for ( $i = 1; $i <= $ncols; $i++ ) { + $column_name = OCIColumnName($stmt,$i); + $column_type = OCIColumnType($stmt,$i); + $column_size = OCIColumnSize($stmt,$i); + print "<TR>"; + print "<TD>$column_name</TD>"; + print "<TD>$column_type</TD>"; + print "<TD>$column_size</TD>"; + print "</TR>"; + } + OCIFreeStatement($stmt); + OCILogoff($conn); + print "</PRE>"; + print "</HTML>\n"; +?> + + See also OCINumCols, OCIColumnType, + and OCIColumnSize. + + + + + + OCIColumnType + Returns the data type of a column. + + + Description + + mixed OCIColumnName + int stmt + int col + + + OCIColumnType returns the data type of the column + corresponding to the column number (1-based) that is passed in. + + + + OCIColumnType + +<?php + print "<HTML><PRE>\n"; + $conn = OCILogon("scott", "tiger"); + $stmt = OCIParse($conn,"select * from emp"); + OCIExecute($stmt); + print "<TABLE BORDER=\"1\">"; + print "<TR>"; + print "<TH>Name</TH>"; + print "<TH>Type</TH>"; + print "<TH>Length</TH>"; + print "</TR>"; + $ncols = OCINumCols($stmt); + for ( $i = 1; $i <= $ncols; $i++ ) { + $column_name = OCIColumnName($stmt,$i); + $column_type = OCIColumnType($stmt,$i); + $column_size = OCIColumnSize($stmt,$i); + print "<TR>"; + print "<TD>$column_name</TD>"; + print "<TD>$column_type</TD>"; + print "<TD>$column_size</TD>"; + print "</TR>"; + } + OCIFreeStatement($stmt); + OCILogoff($conn); + print "</PRE>"; + print "</HTML>\n"; +?> + + See also OCINumCols, OCIColumnName, + and OCIColumnSize. + + + + + + OCIParse + Parse a query and return a statement + + + Description + + int OCIParse + int conn + strint query + + + OCIParse parses the query + using conn. It returns true if the query is + valid, false if not. The query can be any valid + SQL statement. + + + + + OCIError + Return the last error of stmt|conn|global. + If no error happened returns false. + + + + Description + + int OCIError + int stmt|conn + + + OCIError returns the last error found. If the optional + stmt|conn is not provided, the last error encountered + is returned. If no error is found, OCIError returns false. + + + + + OCIInternalDebug + Enables or disables internal debug output. By default it is disabled + + + Description + + void OCIInternalDebug + int onoff + + + OCIInternalDebug enables internal debug output. Set onoff + to 0 to turn debug output off, 1 to turn it on. + +