Textpattern PHP Cross Reference Content Management Systems

Summary: /textpattern/lib/txplib_db.php - 1630 lines - 39814 bytes - Source - Print

Description: Database abstraction layer.

Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

DB:: (46 methods):
__construct()
safe_pfx()
safe_pfx_j()
safe_escape()
safe_escape_like()
safe_query()
safe_delete()
safe_update()
safe_insert()
safe_upsert()
safe_alter()
safe_lock()
safe_unlock()
safe_index()
safe_create_index()
safe_drop_index()
safe_optimize()
safe_repair()
safe_truncate()
safe_drop()
safe_create()
safe_rename()
safe_field()
safe_column()
safe_column_num()
safe_row()
safe_rows()
safe_rows_start()
safe_count()
safe_show()
fetch()
getRow()
getRows()
startRows()
nextRow()
numRows()
getThing()
getThings()
getCount()
getTree()
getRootPath()
getTreePath()
rebuild_tree()
rebuild_tree_full()
db_down()
now()

Class: DB

Initialises a database connection.

__construct()  line: 161
Creates a new link.

safe_pfx($table line: 285
Prefixes a database table's name for use in a query.

Textpattern can be installed to a shared database, this is achieved by
prefixing database tables. This function can be used to add those prefixes to
a known named table when building SQL statements.

Always use this function, or the safe_pfx_j(), when you refer tables in raw
SQL statements, including where clauses, joins and sub-queries.

This function will also quote the table name if necessary.

You don't need to use this function in any of the dedicated "table"
parameters database functions offer. Any table used in a table parameter is
prefixed for you.

return: string The $table with a prefix
param: string $table The database table
safe_pfx_j($table line: 323
Prefixes a database table's name for use in a joined query.

This function prefixes the given table name similarly to safe_pfx(), but also
creates a named, unprefixed, AS alias for it.

The created alias is same as the table name given. This function is here to
help to make joined queries where you need to refer to two or more tables in
a one query.

As with safe_pfx(), you don't need to use this function in any of the
dedicated "table" parameters database functions offer. Any table used in a
table parameter is prefixed for you.

return: string The $table with a prefix
param: string $table The database table, or comma-separated list of tables
safe_escape($in = '')  line: 364
Escapes special characters in a string for use in an SQL statement.

return: string
param: string $in The input string
safe_escape_like($in = '')  line: 385
Escape LIKE pattern's wildcards in a string for use in an SQL statement.

return: string
param: string $in The input string
safe_query($q = '', $debug = false, $unbuf = false)  line: 408
Executes an SQL statement.

return: mixed
param: string $q     The SQL statement to execute
param: bool   $debug Dump query
param: bool   $unbuf If TRUE, executes the statement without fetching and buffering the results
safe_delete($table, $where, $debug = false)  line: 458
Deletes a row from a table.

return: bool FALSE on error
param: string $table The table
param: string $where The where clause
param: bool   $debug Dump query
safe_update($table, $set, $where, $debug = false)  line: 479
Updates a table row.

return: bool FALSE on error
param: string $table The table
param: string $set   The set clause
param: string $where The where clause
param: bool   $debug Dump query
safe_insert($table, $set, $debug = false)  line: 501
Inserts a new row into a table.

return: int|bool The last generated ID or FALSE on error. If the ID is 0, returns TRUE
param: string $table The table
param: string $set   The set clause
param: bool   $debug Dump query
safe_upsert($table, $set, $where, $debug = false)  line: 531
Inserts a new row, or updates an existing if a matching row is found.

return: int|bool The last generated ID or FALSE on error. If the ID is 0, returns TRUE
param: string       $table The table
param: string       $set   The set clause
param: string|array $where The where clause
param: bool         $debug Dump query
safe_alter($table, $alter, $debug = false)  line: 567
Changes the structure of a table.

return: bool FALSE on error
param: string $table The table
param: string $alter The statement to execute
param: bool   $debug Dump query
safe_lock($table, $type = 'write', $debug = false)  line: 586
Locks a table.

The $table argument accepts comma-separated list of table names, if you need
to lock multiple tables at once.

return: bool TRUE if the tables are locked
param: string $table The table
param: string $type  The lock type
param: bool   $debug Dump the query
safe_unlock($debug = false)  line: 609
Unlocks tables.

return: bool TRUE if tables aren't locked
param: bool $debug Dump the query
safe_index($table, $index, $debug = false)  line: 627
Gets an array of information about an index.

return: array|bool Array of information about the index, or FALSE on error
param: string $table The table
param: string $index The index
param: bool   $debug Dump the query
safe_create_index($table, $columns, $name, $index = '', $type = '', $debug = false)  line: 657
Creates an index.

return: bool TRUE if index exists
param: string $table   The table
param: string $columns Indexed columns
param: string $name    The name
param: string $index   The index. Either 'unique', 'fulltext', 'spatial' (default = standard index)
param: string $type    The index type
param: bool   $debug   Dump the query
safe_drop_index($table, $index, $debug = false)  line: 690
Removes an index.

return: bool TRUE if the index no longer exists
param: string $table The table
param: string $index The index
param: bool   $debug Dump the query
safe_optimize($table, $debug = false)  line: 720
Optimises a table.

return: bool FALSE on error
param: string $table The table
param: bool   $debug Dump query
safe_repair($table, $debug = false)  line: 738
Repairs a table.

return: bool   FALSE on error
param: string $table The table
param: bool   $debug Dump query
safe_truncate($table, $debug = false)  line: 756
Truncates a table.

Running this function empties a table completely, resets indexes and the auto
increment value.

return: bool   TRUE if the table is empty
param: string $table The table
param: bool   $debug Dump query
safe_drop($table, $debug = false)  line: 779
Removes a table.

This function removes all data and definitions associated with a table.

return: bool   TRUE if the table no longer exists
param: string $table The table
param: bool   $debug Dump query
safe_create($table, $definition, $options = '', $debug = false)  line: 800
Creates a table.

Creates a table with the given name. This table will be created with
identical properties to core tables, ensuring the best possible compatibility.

return: bool   TRUE if table exists
param: string $table      The table
param: string $definition The create definition
param: string $options    Table options
param: bool   $debug      Dump the query
safe_rename($table, $newname, $debug = false)  line: 832
Renames a table.

return: bool   FALSE on error
param: string $table   The table
param: string $newname The new name
param: bool   $debug   Dump the query
safe_field($thing, $table, $where, $debug = false)  line: 847
Gets a field from a row.

If the query results in multiple matches, the first row returned is used.

return: mixed  The field or FALSE on error
param: string $thing The field
param: string $table The table
param: string $where The where clause
param: bool   $debug Dump query
safe_column($thing, $table, $where = '1', $debug = false)  line: 879
Gets a list of values from a table's column.

return: array
param: string $thing The column
param: string $table The table
param: string $where The where clause
param: bool   $debug Dump query
safe_column_num($thing, $table, $where, $debug = false)  line: 918
Fetch a column as an numeric array.

return: array  Numeric array of column values
param: string $thing The field
param: string $table The table
param: string $where The where clause
param: bool   $debug Dump query
safe_row($things, $table, $where, $debug = false)  line: 945
Gets a row from a table as an associative array.

return: array
param: string $things The select clause
param: string $table  The table
param: string $where  The where clause
param: bool   $debug  Dump query
safe_rows($things, $table, $where, $debug = false)  line: 975
Gets a list rows from a table as an associative array.

When working with large result sets remember that this function, unlike
safe_rows_start(), loads results to memory all at once. To optimise
performance in such situations, use safe_rows_start() instead.

return: array  Returns an empty array if no matches are found
param: string $things The select clause
param: string $table  The table
param: string $where  The where clause
param: bool   $debug  Dump query
safe_rows_start($things, $table, $where, $debug = false)  line: 1010
Selects rows from a table and returns result as a resource.

return: resource|bool A result resource or FALSE on error
param: string        $things The select clause
param: string        $table  The table
param: string        $where  The where clause
param: bool          $debug  Dump query
safe_count($table, $where, $debug = false)  line: 1037
Counts number of rows in a table.

return: int|bool Number of rows or FALSE on error
param: string   $table The table
param: string   $where The where clause
param: bool     $debug Dump query
safe_show($thing, $table, $debug = false)  line: 1056
Shows information about a table.

return: array
param: string   $thing The information to show, e.g. "index", "columns"
param: string   $table The table
param: bool     $debug Dump query
fetch($col, $table, $key, $val, $debug = false)  line: 1079
Gets a field from a row.

This function offers an alternative short-hand syntax to safe_field().
Most notably, this internally manages value escaping.

return: mixed  The field or FALSE on error
param: string $col   The field to get
param: string $table The table
param: string $key   The searched field
param: string $val   The searched value
param: bool   $debug Dump query
getRow($query, $debug = false)  line: 1116
Gets a row as an associative array.

return: array|bool The row's values or FALSE on error
param: string     $query The SQL statement to execute
param: bool       $debug Dump query
getRows($query, $debug = false)  line: 1137
Gets multiple rows as an associative array.

If you need to run simple SELECT queries that select rows from a table,
please see safe_rows() and safe_rows_start() first.

return: array|bool The rows or FALSE on error
param: string     $query The SQL statement to execute
param: bool       $debug Dump query
startRows($query, $debug = false)  line: 1171
Executes an SQL statement and returns results.

This function is identical to safe_query() apart from the missing
$unbuf argument.

return: mixed
param: string $query The SQL statement to execute
param: bool   $debug Dump query
nextRow($r line: 1189
Gets a next row as an associative array from a result resource.

The function will free up memory reserved by the result resource if called
after the last row.

return: array|bool  The row, or FALSE if there are no more rows
param: resource    $r The result resource
numRows($r line: 1219
Gets the number of rows in a result resource.

return: int|bool The number of rows or FALSE on error
param: resource $r The result resource
getThing($query, $debug = false)  line: 1237
Gets the contents of a single cell from a resource set.

return: string|bool The contents, empty if no results were found or FALSE on error
param: string      $query The SQL statement to execute
param: bool        $debug Dump query
getThings($query, $debug = false)  line: 1261
Return values of one column from multiple rows in a num indexed array.

return: array
param: string $query The SQL statement to execute
param: bool   $debug Dump query
getCount($table, $where, $debug = false)  line: 1284
Counts number of rows in a table.

This function is identical to safe_count().

return: int|bool     Number of rows or FALSE on error
param: array|string $table The table/thing to count
param: string       $where The where clause
param: bool         $debug Dump query
getTree($root, $type = 'article', $where = "1 = 1", $tbl = 'txp_category', $depth = true)  line: 1308
Gets a tree structure.

This function is used by categories.

return: array
param: string $root  The roots
param: string $type  The type
param: string $where The where clause
param: string $tbl   The table
getRootPath($target, $type = 'article', $tbl = 'txp_category', $root = 'root')  line: 1387
Gets a target/path/up/to/root array.

This function is used by categories.

return: array
param: string $target The target
param: string $type   The category type
param: string $tbl    The table
param: string $root   The root (excluded)
getTreePath($target, $type, $tbl = 'txp_category')  line: 1425
Gets a tree path up to a target.

This function is used by categories.

return: array
param: string $target The target
param: string $type   The category type
param: string $tbl    The table
rebuild_tree($parent, $left, $type, $tbl = 'txp_category')  line: 1482
Rebuilds a nested tree set.

This function is used by categories.

return: int The next left ID
param: string $parent The parent
param: string $left   The left ID
param: string $type   The category type
param: string $tbl    The table
rebuild_tree_full($type, $tbl = 'txp_category')  line: 1522
Rebuilds a tree.

This function is used by categories.

return: int The next left ID
param: string $type   The category type
param: string $tbl    The table
db_down()  line: 1547
Returns an error page.

This function is used to return a bailout page when resolving database
connections fails. Sends a HTTP 503 error status and displays the last logged
MySQL error message.

return: string HTML5 document
now($type, $update = false)  line: 1586
Replacement for SQL NOW()

This function can be used when constructing SQL SELECT queries as a
replacement for the NOW() function to allow the SQL server to cache the
queries. Should only be used when comparing with the Posted or Expired
columns from the textpattern (articles) table, the Created column from
the txp_file table or the Date column from the txp_link table.

return: string SQL query string partial
param: string $type   Column name, lower case (one of 'posted', 'expires', 'created', 'date')
param: bool   $update Force update

title

Body