DatasourceManager
in package
This abstract class defines the interface through which the seek_quarry program communicates with a database and the filesystem.
Tags
Table of Contents
- $query_log : string
- Used to store statistics about what queries have been run depending on the debug level
- $total_time : int
- Used to store the total time taken to execute queries
- __construct() : mixed
- Sets up the query_log for query statistics
- affectedRows() : int
- Returns the number of rows affected by the last sql statement
- autoIncrement() : string
- Returns string for given DBMS CREATE TABLE equivalent to auto_increment (at least as far as Yioop requires).
- beginTransaction() : mixed
- blobType() : string
- Used when creating databases to set what a blob is If the DBMS is Postgres, there is not BLOB type, only BYTEA
- closeCursor() : mixed
- commit() : mixed
- connect() : mixed
- Connects to a database on a DBMS using data provided or from config.php
- copyRecursive() : mixed
- Recursively copies a source directory to a destination directory
- copyTable() : mixed
- 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.
- disconnect() : mixed
- Closes connections to DBMS
- escapeString() : string
- Used to escape strings before insertion in the database to avoid SQL injection
- exec() : mixed
- Hook Method for execute(). Executes the sql command on the database
- execute() : mixed
- Executes the supplied sql command on the database, depending on debug levels computes query statistics
- fetchArray() : array<string|int, mixed>
- Returns the next row from the provided result set
- fileInfoRecursive() : array<string|int, mixed>
- Returns arrays of filesizes and file modifications times of files in a directory
- insertID() : string
- Returns the ID generated by the last insert statement if table has an auto increment key column
- insertIgnore() : string
- Used to convert a sql string that does an insert statement into a sql string where a duplicate insert is ignored
- integerType() : 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
- limitOffset() : 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.
- pageType() : string
- Used when creating databases to set what type should be used for wiki pages
- serialType() : 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.
- setWorldPermissionsRecursive() : mixed
- Recursively chmod a directory to 0777
- traverseDirectory() : array<string|int, mixed>
- Recursively traverse a directory structure and call a callback function
- unlinkRecursive() : mixed
- Recursively delete a file or directory
Properties
$query_log
Used to store statistics about what queries have been run depending on the debug level
public
string
$query_log
$total_time
Used to store the total time taken to execute queries
public
int
$total_time
Methods
__construct()
Sets up the query_log for query statistics
public
__construct() : mixed
Return values
mixed —affectedRows()
Returns the number of rows affected by the last sql statement
public
abstract affectedRows() : int
Return values
int —the number of rows affected by the last insert, update, delete
autoIncrement()
Returns string for given DBMS CREATE TABLE equivalent to auto_increment (at least as far as Yioop requires).
public
autoIncrement(array<string|int, mixed> $dbinfo) : string
Parameters
- $dbinfo : array<string|int, mixed>
-
contains strings DBMS, DB_HOST, DB_USER, DB_PASSWORD
Return values
string —to achieve auto_increment function for the given DBMS
beginTransaction()
public
abstract beginTransaction() : mixed
Return values
mixed —blobType()
Used when creating databases to set what a blob is If the DBMS is Postgres, there is not BLOB type, only BYTEA
public
blobType(array<string|int, mixed> $dbinfo) : string
Parameters
- $dbinfo : array<string|int, mixed>
-
containing fields for the current DBMS
Return values
string —to use for column type corresponding to a BLOB
closeCursor()
public
abstract closeCursor(mixed $result) : mixed
Parameters
- $result : mixed
Return values
mixed —commit()
public
abstract commit() : mixed
Return values
mixed —connect()
Connects to a database on a DBMS using data provided or from config.php
public
abstract connect([string $db_host = CDB_HOST ][, string $db_user = CDB_USER ][, string $db_password = CDB_PASSWORD ][, string $db_name = CDB_NAME ]) : mixed
Parameters
- $db_host : string = CDB_HOST
-
the hostname of where the database is located (not used in all dbms's)
- $db_user : string = CDB_USER
-
the user to connect as
- $db_password : string = CDB_PASSWORD
-
the password of the user to connect as
- $db_name : string = CDB_NAME
-
the name of the database on host we are connecting to
Return values
mixed —return false if not successful and some kind of connection object/identifier otherwise
copyRecursive()
Recursively copies a source directory to a destination directory
public
copyRecursive(string $source_dir, string $destination_dir) : mixed
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
- $source_dir : string
-
the name of the source directory
- $destination_dir : string
-
the name of the destination directory
Return values
mixed —copyTable()
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.
public
static copyTable(string $from_table, resource $from_dbm, resource $to_table, resource $to_dbm) : mixed
Parameters
- $from_table : string
-
name of the table to be copied from
- $from_dbm : resource
-
database resource for the from table
- $to_table : resource
-
name of the table to be copied to
- $to_dbm : resource
-
database resource for the to table
Return values
mixed —disconnect()
Closes connections to DBMS
public
abstract disconnect() : mixed
Return values
mixed —escapeString()
Used to escape strings before insertion in the database to avoid SQL injection
public
abstract escapeString(string $str) : string
Parameters
- $str : string
-
string to escape
Return values
string —a string which is safe to insert into the db
exec()
Hook Method for execute(). Executes the sql command on the database
public
abstract exec(string $sql[, array<string|int, mixed> $params = [] ]) : mixed
This method operates on either query or data manipulation statements
Parameters
- $sql : string
-
SQL statement to execute
- $params : array<string|int, mixed> = []
-
bind_name => value values to interpolate into the $sql to be executes
Return values
mixed —false if query fails, resource or true otherwise
execute()
Executes the supplied sql command on the database, depending on debug levels computes query statistics
public
execute(string $sql[, array<string|int, mixed> $params = [] ]) : mixed
This method operates either query or data manipulation statements
Parameters
- $sql : string
-
SQL statement to execute
- $params : array<string|int, mixed> = []
-
bind_name => value values to interpolate into the $sql to be executes
Return values
mixed —false if query fails, resource or true otherwise
fetchArray()
Returns the next row from the provided result set
public
abstract fetchArray(resource $result) : array<string|int, mixed>
Parameters
- $result : resource
-
result set reference of a query
Return values
array<string|int, mixed> —the next row from the result set as an associative array in the form column_name => value
fileInfoRecursive()
Returns arrays of filesizes and file modifications times of files in a directory
public
fileInfoRecursive(string $dir[, bool $root_too = true ]) : array<string|int, mixed>
Parameters
- $dir : string
-
directory to get filesizes for
- $root_too : bool = true
-
whether to have an entry for the whole directory too
Return values
array<string|int, mixed> —of fileinfo information for each file in the folder in question
insertID()
Returns the ID generated by the last insert statement if table has an auto increment key column
public
abstract insertID([string $table_name = "" ]) : string
Parameters
- $table_name : string = ""
-
of table of last insert
Return values
string —the ID of the insert
insertIgnore()
Used to convert a sql string that does an insert statement into a sql string where a duplicate insert is ignored
public
insertIgnore(mixed $sql[, array<string|int, mixed> $dbinfo = null ]) : string
Parameters
- $sql : mixed
- $dbinfo : array<string|int, mixed> = null
-
containing fields for the current DBMS (pdo for Postgres) and DB_HOST (DSN connection string to database)
Return values
string —what to use for insert ignore expression
integerType()
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
public
integerType(array<string|int, mixed> $dbinfo) : string
Parameters
- $dbinfo : array<string|int, mixed>
-
containing fields for the current DBMS
Return values
string —to use for column type corresponding to an 64bit int
limitOffset()
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.
public
limitOffset(int $start[, int $num = -1 ][, array<string|int, mixed> $dbinfo = null ]) : string
Parameters
- $start : int
-
starting row to return from if ($num == -1, i.e., not supplied in the call) then this is is the number of rows desired
- $num : int = -1
-
number of rows to return
- $dbinfo : array<string|int, mixed> = null
-
containing fields for how to connect to a database
Return values
string —what to use for for LIMIT OFFSET query with input $limit and $num for the DBMS in question
pageType()
Used when creating databases to set what type should be used for wiki pages
public
pageType(array<string|int, mixed> $dbinfo) : string
Parameters
- $dbinfo : array<string|int, mixed>
-
containing fields for the current DBMS
Return values
string —to use for column type corresponding to wiki page
serialType()
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.
public
serialType(array<string|int, mixed> $dbinfo) : string
Parameters
- $dbinfo : array<string|int, mixed>
-
containing fields for the current DBMS (pdo for Postgres) and DB_HOST (DSN connection string to database)
Return values
string —what to use for serial data type
setWorldPermissionsRecursive()
Recursively chmod a directory to 0777
public
setWorldPermissionsRecursive(string $dir[, bool $chmod_root_too = true ]) : mixed
Parameters
- $dir : string
-
Directory name
- $chmod_root_too : bool = true
-
chmod specified top-level directory as well
Return values
mixed —traverseDirectory()
Recursively traverse a directory structure and call a callback function
public
traverseDirectory(string $dir, function $callback[, bool $root_too = true ]) : array<string|int, mixed>
Parameters
- $dir : string
-
Directory name
- $callback : function
-
Function to call as traverse structure
- $root_too : bool = true
-
whether to have an apply the callback to the whole directory as well
Return values
array<string|int, mixed> —results computed by performing the traversal
unlinkRecursive()
Recursively delete a file or directory
public
unlinkRecursive(string $dir[, bool $delete_root_too = true ]) : mixed
Parameters
- $dir : string
-
file or directory name
- $delete_root_too : bool = true
-
Delete specified top directory as well