SelfHelp WebApp  v2.0.6
A WebApp to Create WebApps for Studies in Human Sciences
BaseDb Class Reference
Inheritance diagram for BaseDb:

Public Member Functions

 __construct ($server, $dbname, $username, $password, $names="utf8")
 
 get_dbh ()
 
 execute_db ($sql)
 
 execute_update_db ($sql, $arguments=array())
 
 query_db ($sql, $arguments=array(), $fetch_style=PDO::FETCH_ASSOC)
 
 query_db_first ($sql, $arguments=array(), $fetch_style=PDO::FETCH_ASSOC)
 
 remove_by_fk ($table, $fk, $id)
 
 remove_by_ids ($table, $ids)
 
 set_db_locale ($locale)
 
 select_table ($table)
 
 select_by_fk ($table, $fk, $id)
 
 select_by_fks ($table, $fks)
 
 select_by_uid ($table, $id)
 
 select_by_uid_join ($table, $id)
 
 insert ($table, $entries, $update_entries=array())
 
 insert_mult ($table, $cols, $data)
 
 update_by_ids ($table, $entries, $ids)
 

Private Attributes

 $dbh = null
 

Detailed Description

Class to handle the global communication with the DB

Author
moiri

Constructor & Destructor Documentation

◆ __construct()

BaseDb::__construct (   $server,
  $dbname,
  $username,
  $password,
  $names = "utf8" 
)

Open connection to mysql database

Parameters
string$server,address of server
string$dbname,name of database
string$username,username
string$password,password
string$names,charset (optional, default: utf8)

Member Function Documentation

◆ execute_db()

BaseDb::execute_db (   $sql)

Exectute an arbitrary query on the db.

Parameters
string$sqlThe query to be executed.
Return values
intThe number of affected rows.

◆ execute_update_db()

BaseDb::execute_update_db (   $sql,
  $arguments = array() 
)

Exectute an arbitrary update query on the db.

Parameters
string$sqlThe query to be executed.
array$argumentsAn associative array with value key pairs where the keys are variable identifiers used in the query (e.g ':id') which will be replaced with the associated value on query execution.
Return values
arrayThe number of affected rows or false if the query failed.

◆ get_dbh()

BaseDb::get_dbh ( )

Return the PDO handler.

Return values
objectThe database handler.

◆ insert()

BaseDb::insert (   $table,
  $entries,
  $update_entries = array() 
)

Insert values into db table.

Parameters
string$tableThe name of the db table.
array$entriesAn associative array of db entries e.g. colname => foo
array$update_entriesAn associative array of db entries e.g. colname => foo. This array indicates which fields to update should the entry already exist.
Return values
intThe inserted id if succeded, false otherwise.

◆ insert_mult()

BaseDb::insert_mult (   $table,
  $cols,
  $data 
)

Insert multiple rows o values into db table.

Parameters
string$tableThe name of the db table.
array$colsAn array of db collumn names.
array$dataA matrix of values.
Return values
intThe last inserted id if succeded, false otherwise.

◆ query_db()

BaseDb::query_db (   $sql,
  $arguments = array(),
  $fetch_style = PDO::FETCH_ASSOC 
)

Exectute an arbitrary select query on the db.

Parameters
string$sqlThe query to be executed.
array$argumentsAn associative array with value key pairs where the keys are variable identifiers used in the query (e.g ':id') which will be replaced with the associated value on query execution.
enum$fetch_styleControls how the next row will be returned to the caller. Refer to the official documentation for more information.
Return values
arrayAn array with all row entries or false if no entry was selected.

Referenced by PageDb\fetch_accessible_pages(), PageDb\fetch_nav_children(), PageDb\fetch_page_fields(), PageDb\fetch_page_sections(), PageDb\fetch_section_children(), and PageDb\fetch_section_fields().

◆ query_db_first()

BaseDb::query_db_first (   $sql,
  $arguments = array(),
  $fetch_style = PDO::FETCH_ASSOC 
)

Exectute an arbitrary select query on the db and return the first matching row.

Parameters
string$sqlThe query to be executed.
array$argumentsAn associative array with value key pairs where the keys are variable identifiers used in the query (e.g ':id') which will be replaced with the associated value on query execution.
enum$fetch_styleControls how the next row will be returned to the caller. Refer to the official documentation for more information.
Return values
arrayAll row entries or false if no entry was selected.

Referenced by PageDb\fetch_field_id(), PageDb\fetch_page_id_by_keyword(), PageDb\fetch_page_info(), PageDb\fetch_page_keyword_by_id(), PageDb\fetch_section_info_by_id(), and PageDb\fetch_user_name().

◆ remove_by_fk()

BaseDb::remove_by_fk (   $table,
  $fk,
  $id 
)

Remove all rows where the foreign key matches.

Parameters
string$tableThe name of the db table.
string$fkThe name of the foreign key.
int$idThe foreign key of the row to be selected
Return values
boolTrue on success, false otherwise.

◆ remove_by_ids()

BaseDb::remove_by_ids (   $table,
  $ids 
)

Remove all rows where the foreign key matches.

Parameters
string$tableThe name of the db table.
array$idsAn associative array of where conditions e.g WHERE $key = $value. The conditions are concatenated with AND.
Return values
boolTrue on success, false otherwise.

◆ select_by_fk()

BaseDb::select_by_fk (   $table,
  $fk,
  $id 
)

Get a single row of a db table by foreign key.

Parameters
string$tableThe name of the db table.
string$fkThe name of the foreign key.
int$idThe foreign key of the row to be selected
Return values
arrayAn array with all row entries or false if no entry was selected

◆ select_by_fks()

BaseDb::select_by_fks (   $table,
  $fks 
)

Get a single row of a db table by foreign key constarints.

Parameters
string$tableThe name of the db table.
array$fksAn associative array of where conditions e.g WHERE $key = $value. The conditions are concatenated with AND.
Return values
arrayAn array with all row entries or false if no entry was selected

◆ select_by_uid()

BaseDb::select_by_uid (   $table,
  $id 
)

Get a single row of a db table by unique id.

Parameters
string$tableThe name of the db table.
int$idThe unique id of the row to be selected.
Return values
arrayAn array with all row entries or false if no entry was selected.

Referenced by select_by_uid_join().

◆ select_by_uid_join()

BaseDb::select_by_uid_join (   $table,
  $id 
)

Get a single row of a data table by unique id and get all names of foreign keys by joining the linked tables. The naming convention to make this work is as follows:

  • primary id keys: 'id'
  • foreign keys: 'id_<table_name>'
Parameters
string$tableThe name of the db table.
int$idThe unique id of the row to be selected.
Return values
arrayAn array with all entries of the row or false if no entry was selected.
Here is the call graph for this function:

◆ select_table()

BaseDb::select_table (   $table)

Get all rows from a table.

Parameters
string$tableThe name of the db table.
Return values
arrayAn array with all row entries or false if no entry was selected.

◆ set_db_locale()

BaseDb::set_db_locale (   $locale)

Set locale time name variable.

Parameters
string$localeThe locale indentifier, e.g. de_CH.

◆ update_by_ids()

BaseDb::update_by_ids (   $table,
  $entries,
  $ids 
)

Update values in db defined by one or several ids.

Parameters
string$tableThe name of the db table.
array$entriesAn associative array of db entries e.g. $["colname1"] = "foo".
array$idsAn associative array of where conditions e.g WHERE $key = $value. The conditions are concatenated with AND.
Return values
booltrue if succeded, false otherwise.

Member Data Documentation

◆ $dbh

BaseDb::$dbh = null
private

The DB handler.

Referenced by get_dbh().


The documentation for this class was generated from the following file: