Show:

Db_Utils Class

Module: Db

This class lets you do things related to databases and db results

Item Index

Methods

Methods

compare_dbRows

(
  • $dbRow1
  • $dbRow2
)
Integer private static

Compare database rows

Parameters:

  • $dbRow1 Array
  • $dbRow2 Array

Returns:

Integer:

dump_table

(
  • $rows
)
static

Dumps as a table

Parameters:

  • $rows Array

filename

(
  • $dirname
  • [$basename=null]
)
String static

Combines a dirname and a basename, using a slash if needed. Use this function to build up paths with the correct DIRECTORY_SEPARATOR.

Parameters:

  • $dirname String

    The part of the the filename to append to. May or may not include a slash at the end.

  • [$basename=null] String optional

    The part of the filename that comes after the slash You can continue to pass more tools as the 3rd, 4th etc. parameters to this function, and they will all be concatenated into one filename.

Returns:

String:

The combined absolute filename. If it does not exist, but the filename appended to the current working directory exists, then the latter is returned.

log

(
  • $message
  • [$level=LOG_NOTICE]
  • [$timestamp=true]
  • [$ident='Db:']
)
static

Append a message to the log

Parameters:

  • $message String

    the message to append

  • [$level=LOG_NOTICE] Integer optional

    see E_NOTICE in the php manual, etc.

  • [$timestamp=true] Boolean optional

    whether to prepend the current timestamp

  • [$ident='Db:'] String optional

    the ident string to prepend to the message

saveTextFile

(
  • $filename
  • $contents
)
Integer static

Saves a text file. Need to enable UTF-8 support here.

Parameters:

  • $filename String

    The name of the file to save to. Can be relative to this file, or full.

  • $contents String

    The text string to save

Returns:

Integer:

The number of bytes saved, or false if not saved

sort

(
  • $dbRows
  • $field_name
)
static

Sort array by given field

Parameters:

  • $dbRows &array
  • $field_name String

split

(
  • $config
)
Boolean static

Split shard partitin to new shards. It takes the full table or single partition and split it to multiple partitions according to the number of provided 'parts'. When doing initioa split 'shard' may be ommited however 'fields' shall be provided

Parameters:

  • $config Q_Tree

    Contains all necessary information for split procedure in the following format:

Returns:

Boolean:

Weather php part of the process completed successfuly

Example:

{
    "plugin": "PLUGINNAME", // the name of plugin - shall be used by app
    "connection": "CONNECTIONNAME", // connection - shall be registered with plugin
    "table": "TABLENAME", // the table to shard
    "class": "CLASSNAME", // the class which is stored in the table
    "fields": {"FIELDNAME": "HASH", "FIELDNAME": "HASH", ...}, // Optional. Used only when starting sharding
        "shard": "SHARDNAME" // Optionsl. The shard to split. If no shards defined or SHARDNAME does not exist the script will fail
        // "parts" can be either array of connections or object {"SHARDNAME": connection, ...}
    "parts": {
        "SHARDNAME": {
            "prefix": "PREFIX",
            "dsn": "DSN",
                ...
        },
        "SHARDNAME": {
            "prefix": "PREFIX",
            "dsn": "DSN",
                "username": "USERNAME",
                "password": "PASSWORD",
                "driver_options": {
                    "3": 2
                }
        },
        ...
    }
}

splitRecover

() static

Attempts to recover interrupted shards split process

take

(
  • $from
  • $parameters
  • [$prefix='']
)
Array static

A very useful function for stripping off only the parameters you need from an array. Use it for passing parameters to functions in a flexible way.

Parameters:

  • $from Array

    The associative array from which to take the parameters from, consisting of param => value. For example the $_REQUEST array.

  • $parameters Array

    An associative array of paramName => defaultValue pairs. If the parameter was not found in the $from array, the default value is used.

  • [$prefix=''] String optional

    If non-empty, then parameter names are prepended with this prefix before searching in $from is done. The prefix is stripped out in the resulting array. Typically used for database rows. If $parameters is empty, ALL items in $from with keys starting with $prefix are returned.

Returns:

Array:

The parameters are stripped off from the $from array, according to the above rules, and returned as an array.

var_export

(
  • $var
)
static

Exports a simple variable into something that looks nice, nothing fancy (for now) Does not preserve order of array keys.

Parameters:

  • $var Mixed&

    the variable to export