Useful Functions

In this chapter we discuss functions defined in the run-time environment that also users writing hooks could find useful.

Database Functions

When executing a hook, you can access some static functions of the ERW class that can simplify your access to the database. Note that all these functions stop the current script and write to the log file in case of an error.

ERW::log(file, line, message, [level]);

Logs a message if the current logging level is equal to or below the one specified in the main configuration file. Possible levels are ERW_DEBUG, ERW_INFO, ERW_WARNING and ERW_ERROR (the default). The first two parameters are usually filled using the PHP macros __FILE__ and __LINE__, respectively.

ERW::quote(string or array);

Quotes a string for SQL processing. Note that, when applied to an array of strings, it will quote by reference the whole array.

ERW::unquote(string);

Undoes what EWR::quote() did (but works by value).

ERW::query(query);

Executes the given query and returns the result. Database errors cause logging and immediate exit.

ERW::select(select query);

It is identical to ERW::query(), but it automatically prefixes its argument with "SELECT ", so you can write things like ERW::select("* from type");.

ERW::getRow(select query);

It is identical to ERW::select(), but it automatically returns the first row of the result set.

ERW::getOne(select query);

It is identical to ERW::getRow(), but it automatically returns the first column of the row. Very useful when you just want a single datum from the database.