Download the PHP package joomla/database without Composer
On this page you can find all versions of the php package joomla/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download joomla/database
More information about joomla/database
Files in joomla/database
Package database
Short Description Joomla Database Package
License GPL-2.0-or-later
Homepage https://github.com/joomla-framework/database
Informations about the package database
The Database Package
Introduction
The Database package is designed to manage the operations of data management through the use of a generic database engine.
Escaping Strings and Input
Strings must be escaped before using them in queries (never trust any variable input, even if it comes from a previous database query from your own data source). This can be done using the escape
and the quote
method.
The escape
method will generally backslash unsafe characters (unually quote characters but it depends on the database engine). It also allows for optional escaping of additional characters (such as the underscore or percent when used in conjunction with a LIKE
clause).
The quote
method will escape a string and wrap it in quotes, however, the escaping can be turned off which is desirable in some situations. The quote
method will also accept an array of strings and return an array quoted and escaped (unless turned off) string.
In the first case, the title variable is simply escaped and quoted. Any quote characters in the title string will be prepended with a backslash and the whole string will be wrapped in quotes.
In the second case, the example shows how to treat a search string that will be used in a LIKE
clause. In this case, the title variable is manually escaped using escape
with a second argument of true
. This will force other special characters to be escaped (otherwise you could set youself up for serious performance problems if the user includes too many wildcards). Then, the result is passed to the quote
method but escaping is turned off (because it has already been done manually).
In the third case, the title variable is an array so the whole array can be passed to the quote
method (this saves using a closure and a )
Shorthand versions are available the these methods:
q
can be used instead ofquote
qn
can be used instead ofquoteName
e
can be used instead ofescape
These shorthand versions are also available when using the Database\DatabaseQuery
class.
Iterating Over Results
The Database\DatabaseIterator
class allows iteration over database results
It allows also to count the results.
Logging
Database\DatabaseDriver
implements the Psr\Log\LoggerAwareInterface
so is ready for intergrating with a logging package that supports that standard.
Drivers log all errors with a log level of LogLevel::ERROR
.
If debugging is enabled (using setDebug(true)
), all queries are logged with a log level of LogLevel::DEBUG
. The context of the log include:
- sql : The query that was executed.
- category : A value of "databasequery" is used.
An example to log error by Monolog
Add this to composer.json
Then we push Monolog into Database instance.
This is the log file:
Installation via Composer
Add "joomla/database": "~3.0"
to the require block in your composer.json and then run composer install
.
Alternatively, you can simply run the following from the command line:
If you want to include the test sources, use