[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/includes/Database/ -> YDB.php (summary)

Aura SQL wrapper for YOURLS that creates the almighty YDB object.

File Size: 618 lines (18 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

YDB:: (44 methods):
  __construct()
  init()
  set_emulate_state()
  get_emulate_state()
  connect_to_DB()
  dead_or_error()
  start_profiler()
  set_html_context()
  get_html_context()
  set_option()
  has_option()
  get_option()
  delete_option()
  set_infos()
  has_infos()
  get_infos()
  delete_infos()
  update_infos_if_exists()
  get_plugins()
  set_plugins()
  add_plugin()
  remove_plugin()
  get_plugin_pages()
  set_plugin_pages()
  add_plugin_page()
  remove_plugin_page()
  get_num_queries()
  get_queries()
  set_installed()
  is_installed()
  mysql_version()
  fetchAffected()
  fetchAll()
  fetchAssoc()
  fetchCol()
  fetchGroup()
  fetchObject()
  fetchObjects()
  fetchOne()
  fetchPairs()
  fetchValue()
  perform()
  fetch_wrapper()
  without_filters()


Class: YDB  - X-Ref

__construct($dsn, $user, $pass, $options)   X-Ref

param: string $dsn     The data source name
param: string $user    The username
param: string $pass    The password
param: array  $options Driver-specific options
since: 1.7.3

init()   X-Ref
Init everything needed

Everything we need to set up is done here in init(), not in the constructor, so even
when the connection fails (e.g. config error or DB dead), the constructor has worked,
and we have a $ydb object properly instantiated (and for instance yourls_die() can
correctly die, even if using $ydb methods)

since: 1.7.3
return: void

set_emulate_state()   X-Ref
Check if we emulate prepare statements, and set bool flag accordingly

Check if current driver can PDO::getAttribute(PDO::ATTR_EMULATE_PREPARES)
Some combinations of PHP/MySQL don't support this function. See
https://travis-ci.org/YOURLS/YOURLS/jobs/271423782#L481

since: 1.7.3
return: void

get_emulate_state()   X-Ref
Get emulate status

since: 1.7.3
return: bool

connect_to_DB()   X-Ref
Initiate real connection to DB server

This is to check that the server is running and/or the config is OK

since: 1.7.3
return: void

dead_or_error(\Exception $exception)   X-Ref
Die with an error message

param: \Exception $exception
since: 1.7.3
return: void

start_profiler()   X-Ref
Start a Message Logger

since: 1.7.3
return: void

set_html_context($context)   X-Ref

param: string $context
return: void

get_html_context()   X-Ref

return: string

set_option($name, $value)   X-Ref

param: string $name
param: mixed  $value
return: void

has_option($name)   X-Ref

param: string $name
return: bool

get_option($name)   X-Ref

param: string $name
return: string

delete_option($name)   X-Ref

param: string $name
return: void

set_infos($keyword, $infos)   X-Ref

param: string $keyword
param: mixed  $infos
return: void

has_infos($keyword)   X-Ref

param: string $keyword
return: bool

get_infos($keyword)   X-Ref

param: string $keyword
return: array

delete_infos($keyword)   X-Ref

param: string $keyword
return: void

update_infos_if_exists($keyword, $infos)   X-Ref

param: string $keyword
param: mixed  $infos
return: void

get_plugins()   X-Ref

return: array

set_plugins(array $plugins)   X-Ref

param: array $plugins
return: void

add_plugin($plugin)   X-Ref

param: string $plugin  plugin filename
return: void

remove_plugin($plugin)   X-Ref

param: string $plugin  plugin filename
return: void

get_plugin_pages()   X-Ref

return: array

set_plugin_pages(array $pages)   X-Ref

param: array $pages
return: void

add_plugin_page( $slug, $title, $function )   X-Ref

param: string   $slug
param: string   $title
param: callable $function
return: void

remove_plugin_page( $slug )   X-Ref

param: string $slug
return: void

get_num_queries()   X-Ref
Return count of SQL queries performed

since: 1.7.3
return: int

get_queries()   X-Ref
Return SQL queries performed

since: 1.7.3
return: array

set_installed($bool)   X-Ref
Set YOURLS installed state

param: bool $bool
since: 1.7.3
return: void

is_installed()   X-Ref
Get YOURLS installed state

since: 1.7.3
return: bool

mysql_version()   X-Ref
Return MySQL version

since: 1.7.3
return: string

fetchAffected(string $statement, array $values = [])   X-Ref
Fetch the number of affected rows

param: string $statement SQL statement to execute
param: array  $values    Optional. Values to bind to the statement. Default empty array.
since: 1.10.4
return: int Number of affected rows

fetchAll(string $statement, array $values = [])   X-Ref
Fetch all rows

param: string $statement SQL statement to execute
param: array  $values    Optional. Values to bind to the statement. Default empty array.
since: 1.10.4
return: array All rows returned by the query

fetchAssoc(string $statement, array $values = [])   X-Ref
Fetch all rows as associative arrays

param: string $statement SQL statement to execute
param: array  $values    Optional. Values to bind to the statement. Default empty array.
since: 1.10.4
return: array All rows as associative arrays

fetchCol(string $statement, array $values = [])   X-Ref
Fetch a single column from all rows

param: string $statement SQL statement to execute
param: array  $values    Optional. Values to bind to the statement. Default empty array.
since: 1.10.4
return: array First column values from all rows

fetchGroup(string $statement, array $values = [], int $style = PDO::FETCH_COLUMN)   X-Ref
Fetch rows grouped by the first column

param: string $statement SQL statement to execute
param: array  $values    Optional. Values to bind to the statement. Default empty array.
param: int    $style     Optional. PDO fetch style constant. Default PDO::FETCH_COLUMN.
since: 1.10.4
return: array Rows grouped by the first column value

fetchObject(string $statement, array $values = [], string $class = 'stdClass', array $args = [])   X-Ref
Fetch a single row as an object

param: string $statement SQL statement to execute
param: array  $values    Optional. Values to bind to the statement. Default empty array.
param: string $class     Optional. Class name for the returned object. Default 'stdClass'.
param: array  $args      Optional. Constructor arguments for the class. Default empty array.
since: 1.10.4
return: object|false Object representing the row, or false if no rows found

fetchObjects(string $statement, array $values = [], string $class = 'stdClass', array $args = [])   X-Ref
Fetch all rows as objects

param: string $statement SQL statement to execute
param: array  $values    Optional. Values to bind to the statement. Default empty array.
param: string $class     Optional. Class name for the returned objects. Default 'stdClass'.
param: array  $args      Optional. Constructor arguments for the class. Default empty array.
since: 1.10.4
return: array All rows as objects

fetchOne(string $statement, array $values = [])   X-Ref
Fetch a single row as an array

param: string $statement SQL statement to execute
param: array  $values    Optional. Values to bind to the statement. Default empty array.
since: 1.10.4
return: array|false Associative array representing the row, or false if no rows found

fetchPairs(string $statement, array $values = [])   X-Ref
Fetch key-value pairs

param: string $statement SQL statement to execute
param: array  $values    Optional. Values to bind to the statement. Default empty array.
since: 1.10.4
return: array Associative array of key-value pairs

fetchValue(string $statement, array $values = [])   X-Ref
Fetch a single value

param: string $statement SQL statement to execute
param: array  $values    Optional. Values to bind to the statement. Default empty array.
since: 1.10.4
return: mixed Single value from the query result

perform(string $statement, array $values = [])   X-Ref
Performs a query with bound values and returns the resulting PDOStatement
You most likely should not use this method directly. Use the fetch_* methods instead.

param: string $statement The SQL statement to perform.
param: array  $values    Values to bind to the query
since: 1.10.4
return: PDOStatement

fetch_wrapper(string $method, ...$args)   X-Ref
Wrapper for all fetch methods, allowing plugins to intercept and modify query results.

param: string $method  The parent fetch method name to call (e.g., 'fetchAll', 'fetchValue')
param: mixed  ...$args Variable number of arguments to pass to the parent method
since: 1.10.4
return: mixed The cached result if available, otherwise the fresh query result

without_filters(callable $callback)   X-Ref
Execute a callback with filters temporarily disabled

This method allows bypassing the plugin filter system for the duration of the callback execution. Useful to
prevent infinite loops when a filter needs to call the original method without re-triggering itself.

Example usage:
$ydb = yourls_get_db('write-get_from_cache');
$result = $ydb->withoutFilters(function($db) use ($method, $args) {
return $db->fetch_wrapper($method, ...$args);
});

param: callable $callback
since: 1.10.4
return: mixed



Generated: Sat Aug 22 05:12:18 2026 Cross-referenced by PHPXref 0.7.1