Db_Utils Class
This class lets you do things related to databases and db results
Item Index
Methods
- compare_dbRows static
- dump_table static
- filename static
- log static
- saveTextFile static
- sort static
- split static
- splitRecover static
- take static
- var_export static
Methods
compare_dbRows
-
$dbRow1
-
$dbRow2
Compare database rows
Parameters:
-
$dbRow1
Array -
$dbRow2
Array
Returns:
dump_table
-
$rows
Dumps as a table
Parameters:
-
$rows
Array
filename
-
$dirname
-
[$basename=null]
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
StringThe part of the the filename to append to. May or may not include a slash at the end.
-
[$basename=null]
String optionalThe 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:
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:']
Append a message to the log
Parameters:
-
$message
Stringthe message to append
-
[$level=LOG_NOTICE]
Integer optionalsee E_NOTICE in the php manual, etc.
-
[$timestamp=true]
Boolean optionalwhether to prepend the current timestamp
-
[$ident='Db:']
String optionalthe ident string to prepend to the message
saveTextFile
-
$filename
-
$contents
Saves a text file. Need to enable UTF-8 support here.
Parameters:
-
$filename
StringThe name of the file to save to. Can be relative to this file, or full.
-
$contents
StringThe text string to save
Returns:
The number of bytes saved, or false if not saved
sort
-
$dbRows
-
$field_name
Sort array by given field
Parameters:
-
$dbRows
&array -
$field_name
String
split
-
$config
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_TreeContains all necessary information for split procedure in the following format:
Returns:
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='']
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
ArrayThe associative array from which to take the parameters from, consisting of param => value. For example the $_REQUEST array.
-
$parameters
ArrayAn associative array of paramName => defaultValue pairs. If the parameter was not found in the $from array, the default value is used.
-
[$prefix='']
String optionalIf 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:
The parameters are stripped off from the $from array, according to the above rules, and returned as an array.
var_export
-
$var
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