\seekquarry\yioop\models\datasourcesDatasourceManager

This abstract class defines the interface through which the seek_quarry program communicates with a database and the filesystem.

Summary

Methods
Properties
Constants
__construct()
connect()
disconnect()
exec()
affectedRows()
insertID()
fetchArray()
escapeString()
execute()
unlinkRecursive()
setWorldPermissionsRecursive()
fileInfoRecursive()
copyRecursive()
traverseDirectory()
autoIncrement()
serialType()
integerType()
insertIgnore()
limitOffset()
copyTable()
$query_log
$total_time
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$query_log

$query_log : string

Used to store statistics about what queries have been run depending on the debug level

Type

string

$total_time

$total_time : integer

Used to store the total time taken to execute queries

Type

integer

Methods

__construct()

__construct() 

Sets up the query_log for query statistics

connect()

connect(string  $db_host = \seekquarry\yioop\configs\DB_HOST, string  $db_user = \seekquarry\yioop\configs\DB_USER, string  $db_password = \seekquarry\yioop\configs\DB_PASSWORD, string  $db_name = \seekquarry\yioop\configs\DB_NAME) : mixed

Connects to a database on a DBMS using data provided or from config.php

Parameters

string $db_host

the hostname of where the database is located (not used in all dbms's)

string $db_user

the user to connect as

string $db_password

the password of the user to connect as

string $db_name

the name of the database on host we are connecting to

Returns

mixed —

return false if not successful and some kind of connection object/identifier otherwise

disconnect()

disconnect() 

Closes connections to DBMS

exec()

exec(string  $sql, array  $params = array()) : mixed

Hook Method for execute(). Executes the sql command on the database

This method operates on either query or data manipulation statements

Parameters

string $sql

SQL statement to execute

array $params

bind_name => value values to interpolate into the $sql to be executes

Returns

mixed —

false if query fails, resource or true otherwise

affectedRows()

affectedRows() : integer

Returns the number of rows affected by the last sql statement

Returns

integer —

the number of rows affected by the last insert, update, delete

insertID()

insertID(string  $table_name = "") : string

Returns the ID generated by the last insert statement if table has an auto increment key column

Parameters

string $table_name

of table of last insert

Returns

string —

the ID of the insert

fetchArray()

fetchArray(resource  $result) : array

Returns the next row from the provided result set

Parameters

resource $result

result set reference of a query

Returns

array —

the next row from the result set as an associative array in the form column_name => value

escapeString()

escapeString(string  $str) : string

Used to escape strings before insertion in the database to avoid SQL injection

Parameters

string $str

string to escape

Returns

string —

a string which is safe to insert into the db

execute()

execute(string  $sql, array  $params = array()) : mixed

Executes the supplied sql command on the database, depending on debug levels computes query statistics

This method operates either query or data manipulation statements

Parameters

string $sql

SQL statement to execute

array $params

bind_name => value values to interpolate into the $sql to be executes

Returns

mixed —

false if query fails, resource or true otherwise

unlinkRecursive()

unlinkRecursive(string  $dir, boolean  $deleteRootToo = true) 

Recursively delete a directory

Parameters

string $dir

Directory name

boolean $deleteRootToo

Delete specified top directory as well

setWorldPermissionsRecursive()

setWorldPermissionsRecursive(string  $dir, boolean  $chmodRootToo = true) 

Recursively chmod a directory to 0777

Parameters

string $dir

Directory name

boolean $chmodRootToo

chmod specified top-level directory as well

fileInfoRecursive()

fileInfoRecursive(string  $dir, boolean  $rootToo = true) : array

Returns arrays of filesizes and file modifcations times of files in a directory

Parameters

string $dir

directory to get filesizes for

boolean $rootToo

whether to have an entry for the whole directory too

Returns

array —

of fileinfo information for each file in the folder in question

copyRecursive()

copyRecursive(string  $source_dir, string  $destination_dir) 

Recursively copies a source directory to a destination directory

It would have been cool to use traverseDirectory to implement this, but it was a little bit too much of a stretch to shoehorn the code to match

Parameters

string $source_dir

the name of the source directory

string $destination_dir

the name of the destination directory

traverseDirectory()

traverseDirectory(string  $dir, \seekquarry\yioop\models\datasources\function  $callback, boolean  $rootToo = true) : array

Recursively traverse a directory structure and call a callback function

Parameters

string $dir

Directory name

\seekquarry\yioop\models\datasources\function $callback

Function to call as traverse structure

boolean $rootToo

whether to have an apply the callback to the whole directory as well

Returns

array —

results computed by performing the traversal

autoIncrement()

autoIncrement(array  $dbinfo) : string

Returns string for given DBMS CREATE TABLE equivalent to auto_increment (at least as far as Yioop requires).

Parameters

array $dbinfo

contains strings DBMS, DB_HOST, DB_USER, DB_PASSWORD

Returns

string —

to achieve auto_increment function for the given DBMS

serialType()

serialType(array  $dbinfo) : string

Used to return the database column type for a column that can be used to do autoincrementing. Usually this will just be INTEGER, however, for Postgres is SERIAL.

Parameters

array $dbinfo

containing fields for the current DBMS (pdo for Postgres) and DB_HOST (DSN connection string to database)

Returns

string —

what to use for serial data type

integerType()

integerType(array  $dbinfo) : string

Used when creating databases to set what an integer is If the DBMS is sqlite, there is not BIGINT type, only INTEGER which can be 8 bytes

Parameters

array $dbinfo

containing fields for the current DBMS

Returns

string —

to use for column type corresponding to an 64bit int

insertIgnore()

insertIgnore(  $sql, array  $dbinfo) : string

Used to convert a sql string that does an insert statement into a sql string where a duplicate insert is ignored

Parameters

$sql
array $dbinfo

containing fields for the current DBMS (pdo for Postgres) and DB_HOST (DSN connection string to database)

Returns

string —

what to use for insert ignore expression

limitOffset()

limitOffset(integer  $start, integer  $num = -1, array  $dbinfo = null) : string

How a daabase can perform LIMIT OFFSET queries is not standardized between DBMS's. This method take a $start, a $num, and a $dbinfo and returns the string that would restrict a query to show $num many rows starting at $start. In the case that $num is not provided then it returns the string represent returning the first $start many rows. In the case that $dbinfo is not provided the current Yioop default database is used.

Parameters

integer $start

starting row to return from if ($num == -1, i.e., not supplied in the call) then this is is the number of rows desired

integer $num

number of rows to return

array $dbinfo

containing fields for how to connect to a database

Returns

string —

what to use for for LIMIT OFFSET query with input $limit and $num for the DBMS in question

copyTable()

copyTable(string  $from_table, resource  $from_dbm, resource  $to_table, resource  $to_dbm) 

Copies the contents of from_table in the first database into the to a to_table of suitable schema in a second database. It assumes the table exists in both databases, both have the same number of columns, etc.

Parameters

string $from_table

name of the table to be copied from

resource $from_dbm

database resource for the from table

resource $to_table

name of the table to be copied to

resource $to_dbm

database resource for the to table