 |
|
Auxiliary Methods
Oracle Tips by Burleson Consulting |
During the discussion of the connect and fetch
methods, several other methods were used without explaining them;
with the exception of the discussion of portability methods and the
numRows method, now presented here in a systematic fashion:
int
DB_Result::numRows()
This method returns the number of rows returned by
the query. It is enabled by setting the DB_PORTABILITY_NUMROWS option,
and can only be called before the first fetch. After that, the value
is not defined.
array DB_Common::tableInfo($table)
This method returns the description for a table or
result set in the variable $table. Elements of the resulting
descriptor array are associative arrays with the following elements:
Element |
Description |
Accessed By |
Table name |
Table being described |
table |
Column name |
Column described by this descriptor |
name |
Column type |
Type of the column |
type |
Column length |
Length of the column (in bytes) |
Length |
Column flags |
NOT NULL or
PRIMARY KEY |
Flags |
Table 4.2:
Elements for associative arrays.
The csr2html() function uses the tableInfo()method to obtain column names in order to use them as the
headers for the HTML table.
int
DB_Result::numCols()
This method is also used in the csr2html()
function to get the number of columns in the query.
integer
DB_Common::affectedRows()
This method returns the number of rows affected by
the last DELETE, UPDATE or INSERT statement. It returns 0 for queries.
boolean
DB_Result::free()
This method frees the memory associated with the
result set/statement handle. In the OCI8 module, the analogous
operation is oci_free_statement() or oci_free_descriptor().
Calling free does not delete the variable, it just closes the cursor
and relinquishes its memory. The cursor can still be reopened.
mixed
DB_Common::quoteSmart($in)
This is an interesting function in that
different databases have different quoting conventions. The most
frequent problem arises with the single quotes, the ANSI SQL
delimiter for the VARCHARand the
CHARdatabase types. Different
databases have different conventions. For the string, E. A. Poe’s
Raven, Oracle would need this: 'E.A. Poe's Raven'. The single
quote is written twice so Oracle understands that it is not a string
delimiter.
Other databases perform the same task by adding a
backslash character (\). At any rate, the smart quoting function is
advanced enough to know which database it is being used against and to
use the corresponding quoting conventions. It has a sister function in
Perl DBI, simply called “quote”.
boolean
DB_Common::Commit()
boolean DB_Common::Rollback()
These two methods are self-explanatory. They
implement commit and rollback database operations.
Methods belonging to the DB_Commonclass are accessed through a database connection
descriptor. Methods belonging to the DB_Result class are accessed
through the result set/statement descriptors.
SEE CODE DEPOT FOR FULL SCRIPTS
http://www.rampant-books.com/book_2005_2_php_oracle.htm
 |
Expert Remote DBA
BC is America's oldest and largest Remote DBA Oracle support
provider. Get real Remote DBA experts, call
BC Remote DBA today. |
 |
|