Class db

Description

Class contains contains methods for connecting to a mysql database with PDO and doing basic crud operations and simple search operations.

Almost any build in modules extends this class.

Located in /lib/db.php (line 17)


	
			
Direct descendents
Class Description
grid Class contains contains class for creating forms from a db tables schema
moduleInstaller class for installing a module or upgrading it.
mySqlForm Class contains contains class for creating forms from a db tables schema
layout class for creating layout, which means menus and blocks class also loads template in its constructor.
Variable Summary
static false|object $dbh
static array $debug
Method Summary
static array getDebug ()
static array prepareToPost ()
db __construct ()
void connect ()
boolean delete (string $table, string $fieldname, string $search)
void fatalError (string $msg)
int getNumRows (string $table, [ $where = null])
boolean insert (string $table, array $values, [ $bind = null])
object the rawQuery (string $sql)
array select (string $table, [string $fieldname = null], [string|array $search = null], [array $fields = null])
array|false selectAll (string $table, [array $fields = null], [array $search = null], [int $from = null], [int $limit = null], [string $order_by = null], [asc $asc = null])
array|0 selectOne (string $table, [string $fieldname = null], [string $search = null], [array $fields = null])
array selectQuery (string $sql)
array simpleSearch (string $table, string $match, string $search, string $select, int $from, int $limit)
int simpleSearchCount (string $table, string $match, string $search)
int update (string $table, array $values, int $search, [ $bind = null])
Variables
static false|object $dbh = false (line 24)

Database handle for the database connection.

static $dbh that holds the connection to the database

static array $debug = array() (line 30)
  • var: holds all sqlstatements when in debug mode.
Methods
static getDebug (line 44)
  • return: all sql statements as an array
static array getDebug ()
static prepareToPost (line 427)

Method for preparing raw

  1. $_POST vars
for execution

  • return: values to use in update and insert sql commands. we do not use 'submit' button and 'captcha'.
  • access: public
static array prepareToPost ()
Constructor __construct (line 36)

constructor will try to call method connect

  • access: public
db __construct ()

Redefined in descendants as:
  • grid::__construct() : constructer. Here we set the table to use
  • moduleInstaller::__construct() : constructor which will take the module to install, upgrade or delete as param and set info about module to be installed, upgraded, etc.
  • mySqlForm::__construct() : constructor which sets the table and fields to use from database when creating the form.
  • layout::__construct() : constructer method where we init our uri object and checks users credentials (admin / user) thus generating accurate menus for each group.
connect (line 55)

Method for connecting a mysql database if a connection is open we use that connection connection string is read from config/config.ini

  • access: public
void connect ()
delete (line 152)

Method for deleting from a database table

  • return: true on succes or false on failure
  • access: public
boolean delete (string $table, string $fieldname, string $search)
  • string $table: table the database table to delete from .e.g. auth
  • string $fieldname: fieldname the where clause e.g. id
  • string $search: search which rows should be deleted (3) e.g. delete from 'auth' Where id = 3
fatalError (line 451)

Method for showing errors

  • access: protected
void fatalError (string $msg)
  • string $msg: msg the message to show with the backtrace
getNumRows (line 370)

Method for counting rows in a table

  • return: num_rows number of rows
  • access: public
int getNumRows (string $table, [ $where = null])
  • string $table: table to count number of rows in
  • $where
insert (line 234)

Method for inserting values into a table

  • return: true or false
  • access: public
boolean insert (string $table, array $values, [ $bind = null])
  • string $table: table the table to insert into
  • array $values: values to insert, .e.g
    1. array ('username' => 'test''password' => md5('test'))
  • $bind
rawQuery (line 415)

Method for doing a raw query. Anything will go

  • return: stmt object returned from the query
  • access: public
object the rawQuery (string $sql)
  • string $sql: the query to execute
select (line 108)

Method for easy selecting from one table

  • return: fetched
  • access: public
array select (string $table, [string $fieldname = null], [string|array $search = null], [array $fields = null])
  • string $table: table the tablename (auth)
  • string $fieldname: fieldname the field to search from (username)
  • string|array $search: search simple search conditions for the fieldname (admin) 'select * from auth where username = admin' or
  • array $fields: the fields to select else * 'select id, title ... '
selectAll (line 175)

Method for seleting all with the options for adding a limit and a order

  • return: rows ASSOC array containing the selected row or false
  • access: public
array|false selectAll (string $table, [array $fields = null], [array $search = null], [int $from = null], [int $limit = null], [string $order_by = null], [asc $asc = null])
  • string $table: table the table were we want to select all from
  • array $fields: fields to select
  • array $search: an array with search options e.g.
    1. array ('username' => 'admin''email' => 'dennis@coscms.org');
  • int $from: from where from do we select
  • int $limit: limit set per select
  • string $order_by: order_by field to order by
  • asc $asc: boolean (1 or 0)
selectOne (line 87)

Method for selecting one row for a table.

  • return: the fetched row or 0 if no rows matched the search
  • access: public
array|0 selectOne (string $table, [string $fieldname = null], [string $search = null], [array $fields = null])
  • string $table: the tablename to select from (e.g. auth)
  • string $fieldname: fieldname the field to search from (e.g username)
  • string $search: simple search conditions for the fieldname (e.g. admin) 'select * from auth where username = admin'
  • array $fields: fields the fields to select else *
selectQuery (line 400)

Method for performing a direct selectQuery, e.g. if we are joinging rows

  • return: the rows found
  • access: public
array selectQuery (string $sql)
  • string $sql: The query to execute
simpleSearch (line 268)

Method for doing a simple full-text mysql search in a database table

  • return: rows FETCH_ASSOC array of rows
  • access: public
array simpleSearch (string $table, string $match, string $search, string $select, int $from, int $limit)
  • string $table: table the table to search e.g. 'article'
  • string $match: match what to match, e.g 'title, content'
  • string $search: select what to select e.g. '*'
  • string $select: search what to search for e.g 'some search words'
  • int $from: from where to start getting the results
  • int $limit: limit how many results to fetch e.g. 20
simpleSearchCount (line 301)

Method for counting rows when searching a mysql table with full-text

  • return: num rows of search results from used full-text search
  • access: public
int simpleSearchCount (string $table, string $match, string $search)
  • string $table: table the table to search e.g. 'article'
  • string $match: match what to match, e.g 'title, content'
  • string $search: search what to search for e.g 'some search words'
update (line 323)

Function for updating a row in a table

  • return: value of last updated row
  • access: public
int update (string $table, array $values, int $search, [ $bind = null])
  • string $table: table the table to insert into
  • array $values: values to update
  • int $search: primary id of row to be updated e.g array ('username' => 'test', 'password' => md5('test'))
  • $bind

Documentation generated on Fri, 17 Dec 2010 17:56:33 +0100 by phpDocumentor 1.4.3