Dbal.sql query
From phpBB Development Wiki
dbal::sql_query –– Run an SQL Query
Contents |
Description
resource dbal::sql_query ( string $query , int $cache_ttl )
For selecting basic data from the database, the function sql_query() is enough. If you want to use any variable in your query, you should use (If it isn't a integer) dbal::sql_escape to be sure the data is safe. Defined in dbal_* class.
Parameters
| Parameter | Usage |
|---|---|
| query | Contains the SQL query which shall be executed. |
| cache_ttl (Optional) | Either 0 to avoid caching or the time in seconds which the result shall be kept in cache. |
Return Values
Returns a result object or FALSE on failure.
The returned result resource should be passed to $db->sql_fetchrow(), $db->sql_fetchrowset() or other functions for dealing with result tables, to access the returned data.
Examples
Example #1
Basic usage.
$integer = 0;
$data = "This is ' some data";
$sql = 'SELECT *
FROM ' . POSTS_TABLE . '
WHERE post_id = ' . (int) $integer . "
AND post_text = '" . $db->sql_escape($data) . "'";
$result = $db->sql_query($sql);

