constructor __construct [line 98]
GALDatabase __construct(
string
$host, string
$user, string
$pw, string
$db)
|
|
Creates a GALDatabase object.
The constructor doesn't connect to the database, this must be done with connect() or pconnect().
Parameters:
destructor __destruct [line 117]
Destroy a GALDatabase object.
This method is automatically called when a GALDatabase object is deleted, e.g. with unset() or the scope of a local variable is left. Usually there's no need for programmers to call it by hand. To disconnect a database connection, use close().
method affected_rows [line 184]
Returns the number of rows that were affected by the last query.
This method is a wrapper for mysql_affected_rows().
Tags:
method buildResult [line 539]
method buildTable [line 562]
method cleanName [line 320]
string cleanName(
string
$string)
|
|
Remove characters from the given string that might mangle a SQL query.
Used to escape table and field names in SQL queries if they aren't given as string constants, but e.g. read from a configuration file or passed as function argument. This method triggers an E_USER_NOTICE if it finds a character that is going to be removed.
Tags:
Parameters:
method close [line 195]
Closes the connection.
If this object is connected, a currently running transaction is committed and the connection is closed with mysql_close(). If this object isn't connected, nothing happens.
method commit [line 472]
method connect [line 218]
Connects to the database server.
This method uses the information given in the constructor to connect to a database server. If connnecting fails, a GAL_EDatabase is thrown.
method connected [line 157]
Checks if GALDatabase::handle is set.
method deleteDelayed [line 459]
void deleteDelayed(
string
$file)
|
|
Deletes a file only after the transaction succeeds.
This method was introduced, because sometimes a file is associated with a database entity, and when deleting the database entity, the file has to be deleted, too. If you want to delete the entity within a transaction, one has to make sure that the whole operation, including the deletion of the file, can be rolled back. The solution implemented here is to delete the file after committing the transaction. This can result in orphan files (when deleting them fails), but in many cases this is better than a missing file. If called while the database is inside a transaction, the file or directory is stored in toDelete and deleted after the transaction is committed. If deleting fails, only warning messages are generated, but the transaction succeeds. If the database isn't inside a transaction, the file is deleted immediately.
Parameters:
method errno [line 261]
Wrapper for mysql_errno().
Tags:
method error [line 269]
Wrapper for mysql_error().
Tags:
method escape [line 301]
string escape(
string
$string)
|
|
Use mysql_real_escape_string() to escape 'evil' characters.
This method calls mysql_real_escape_string() with the given string and the current database connection. It fails and throws a GAL_EDatabase if this database object isn't connected.
Tags:
Parameters:
method executeDeletion [line 491]
Execute the delayed deletion of files.
This method loops throuhg all files stored in toDelete and tries to delete them. On failure it triggers an error message. Finally toDelete is made empty.
Tags:
method getResultFactory [line 553]
Returns the factory to construct results.
method getTableFactory [line 576]
Returns the factory to construct tables.
method last_insert_id [line 277]
Wrapper for mysql_insert_id().
Tags:
method list_fields [line 286]
resource list_fields(
string
$tableName)
|
|
Wrapper for mysql_list_fields().
Parameters:
method pconnect [line 239]
Opens a persistent connection to the database server.
This method is similar to connect(), but instead of mysql_connect() it uses mysql_pconnect().
method query [line 363]
Queries the database.
Submits the given query to the database and returns the result as GALResult instead of a MySQL resource.
Tags:
Parameters:
method rawQuery [line 341]
resource rawQuery(
string
$querystring)
|
|
Wrapper for mysql_query().
This method calls mysql_query() with the given querystring on this connection.
Tags:
Parameters:
method reconnect [line 167]
Closes the current connection and open a new one.
This method forces committing a currently running transaction, closes the current connection and reopens it.
method rollback [line 514]
Roll back the current transaction.
This method immediately submits "ROLLBACK" to the database, sets GALDatabase::rollingBack to TRUE and decreases $transactionNestLevel by one. When rolling back, this connection only accepts rollback() until $transactionNestLevel has reached 0.
Parameters:
method setResultFactory [line 546]
Sets the factory to construct results.
Parameters:
method setTableFactory [line 569]
Sets the factory to construct tables.
Parameters:
method startTransaction [line 435]
Starts a SQL transaction.
This method submits "START TRANSACTION" to the database. As a useful extension to the SQL standard it supports nested transactions, i.e. transactions within transactions. This requires that for every startTransaction() commit() or rollback() is called. Internally, only the first call submits "START TRANSACTION", the subsequent calls increase $transactionNestLevel. When calling commit(), $transactionNestLevel is decreased. The transaction is committed to the database as soon as $transactionNestLevel has reached 0 without errors. If a transaction fails, a "ROLLBACK" is submitted immediately, but it is required that rollback() is called until $transactionNestLevel has reached 0. In the mean time this connection won't accept normal queries, commit() or startTransaction(). An easy way to achieve this is to use exception handling. Note that rollback() automatically re-throws the exception given as argument!
function aa(GALDatabase $db) {
try {
$db->rawQuery("INSERT INTO `foo` (`bar`, `blubb`) VALUES ('42', 'bla')");
$db->rawQuery("DELETE FROM `foo` WHERE `bar`<'42'");
if (!everythingOK()) { // whatever additional error handling you want
throw new Exception('Something failed.');
}
}
catch (Exception $e) {
echo $e;
}
}
function bb(GALDatabase $db) {
try {
$db->rawQuery("REPLACE INTO `example` (`ID`, `value`) VALUES ('13', 'something')");
aa($db);
if (somethingFailed()) {
throw new Exception('Ooops!');
}
}
catch (Exception $e) {
echo $e;
}
}
method table [line 376]
Constructs a
GALTable object that references the table with the given name in this database.
Tags: