Page 246 - DCAP402_DCAO204_DATABASE MANAGEMENT SYSTEM_MANAGING DATABASE
P. 246
Unit 14: Application Development and Administration
Notes
General Handle Methods
Name Usage Description
err() $result = $handle->err(); Gets the error code returned from the database.
errstr() $result = $handle->errstr(); Gets the error message returned from the database.
state() $state = $handle->state(); Gets the SQLSTATE error code.
trace() $handle->trace ($level); Provides tracing functionality such that the $file is
$handle->trace ($level, $file); appended to with trace information. A Level 0 rating
disables tracing and a level 2 tracing provides a
detailed trace.
Database Handle Methods
Name Usage Description
prepare() $statementHandle = dataSourceHandle Prepares a statement for execution.
-> prepare($sql);
do() $rowCount = $databaseHandle -> Prepares and executes an SQL statement
do($sql); and returns the number of rows returned.
commit() $rowCount = $databaseHandle -> Makes permanent the last set of database
commit(); changes if supported.
rollback() $rowCount = $databaseHandle -> Undoes uncommitted changes if
rollback() supported.
disconnect() $rowCount = $databaseHandle - Disconnects from the database.
>disconnect()
ping() $rowCount = $databaseHandle - > Tries to figure out if the database server is
ping() still available.
quote() $sql = $databaseHandle - > Spiffys up a string for an SQL statement.
quote($string);
Statement Handle Methods
Name Usage Description
execute() $value = $statementHandle -> Executes a prepared statement.
execute();
fetchrow_arrayRef $arrayRef = $statementHandle -> Gets the next row of data as a reference to
() fetchrow_arrayref(); an array holding the column values.
fetchrow_array() @array = $statementHandle -> Gets the next row of data as an array.
fetchrow_array();
fetchrow_hashref( $hashRef = $statementHandle -> Gets the next row of data in which the
) fetchrow_hashRef(); keys to the hash reference are the column
names and the values are the column
values.
fetchall_arrayref() $reference = $statementHandle -> Gets all the rows as references in a
fetchall_arrayref() referenced array.
Notes There are all sorts of other more complex methods such as binding and error
handling, but you should consult the documentation and the DBI tutorial referenced above.
These topics are a bit beyond the scope of this tutorial.
14.2.6 Getting the Pieces
So now that we understand what it is that we are building, let’s continue by assembling the tools
and raw material.
LOVELY PROFESSIONAL UNIVERSITY 239