Class dbc

Description

StockManiac Database Connection (DBC)

Establish connection to the DBMS and provide lower level public functionality for to executing SQL queries in a abstracted manner. As of now it utilizes the MySQLi extension build into PHP.

Located in /lib/dbc.class.php (line 47)

session
   |
   --gui
      |
      --dbc
Direct descendents
Class Description
 class dbi StockManiac Database Interface (DBI)
Variable Summary
 string $sql_error
 mysqli $_db
 mysqli_result $_result
Method Summary
 void __construct ([string $user = MYSQL_USER], [string $pass = MYSQL_PASS], [string $schema = MYSQL_DB], [boolt $no_parent_constructor = false])
 bool sql (string $sql, [bool $die_on_failure = TRUE])
 string sql_escape_string (string &$str, [bool $k = false])
 array sql_get_indexedlist_result ([int $key = 0], [int $val = 1])
 array sql_get_objectarray_result (string $class)
 object sql_get_object_result (string $class)
 array sql_get_result ()
 bool sql_script (string $file, [bool $die_on_failure = true])
Variables
int $sql_affected_rows (line 82)

Number of records affected by the last query.

Useful to check in advance whether the query did actually return something.

string $sql_error (line 110)

Human readable error string returned by the DBMS (mostly). If set this should always indicate some sort of lower level SQL problem.

int $sql_execution_time (line 95)

Execution time of last query, in microseconds.

mysqli $_db (line 57)

Database Connection

mysqli_result $_result (line 67)

Query Result Object

Inherited Variables

Inherited from gui

gui::$themes
gui::$_smarty

Inherited from session

session::$err
Methods
Constructor __construct (line 132)
  • access: public
  • uses: MYSQL_USER
  • uses: MYSQL_PASS
  • uses: MYSQL_HOST
  • uses: MYSQL_DB
void __construct ([string $user = MYSQL_USER], [string $pass = MYSQL_PASS], [string $schema = MYSQL_DB], [boolt $no_parent_constructor = false])
  • string $user
  • string $pass
  • string $schema
  • boolt $no_parent_constructor: FIXME:
    • the $no_parent_constructor parameter is a workaround the fact that this call fails if dbc is instanciated directly, ie in cli mode
    • logically dbc should not inherit gui, rather stockmaniac should inherit from both: gui and dbc (dbi actually), but inheritance from multiple classes is not supported in PHP5

Redefinition of:
gui::__construct()
Constructor

Redefined in descendants as:
sql (line 204)

Execute SQL Statement. Returns true on success, false on failure.

The resulting data (if any) can be fetched through one of the public sql_get_*() methods.

bool sql (string $sql, [bool $die_on_failure = TRUE])
  • string $sql
  • bool $die_on_failure
sql_escape_string (line 170)

Escape referenced string to make it 'sql safe'. Useful as callback.

  • access: public
string sql_escape_string (string &$str, [bool $k = false])
  • string &$str
  • bool $k
sql_get_array_result (line 535)

Return the entire result set in one array or false.

array sql_get_array_result ()
sql_get_indexedlist_result (line 586)

Return a indexed list from result set or false on failure.

result is of the form

  1. arrayKEY VALUE
.

By default the first column is used as key and the second column as value (you specify other columns with $key and/or $val). All other columns that may have been returned by the query are ignored. This method is useful to generate input for HTML <<option>> elements.

array sql_get_indexedlist_result ([int $key = 0], [int $val = 1])
  • int $key
  • int $val
sql_get_objectarray_result (line 556)

Return the entire result set as array of $class objects

array sql_get_objectarray_result (string $class)
  • string $class
sql_get_object_result (line 520)

Return single row from SQL result as object of $class.

$class should usually be a vo_* or dao_* class and should match with the fields returned by the sql query.

object sql_get_object_result (string $class)
  • string $class
sql_get_result (line 505)

Return single row from SQL result. Useful in while constructs.

array sql_get_result ()
sql_max_packet_size (line 610)

Determine how much we can send at once to the DBMS. Return number of bytes.

NOTE: the result is safe enough for caching during a session, for the sake of performance :-)

  • access: public
int sql_max_packet_size ()
sql_script (line 263)

Execute SQL Statements from $file.

Returns the number of SQL statements processd on success or dies if any* statement in $file fails. Set * $die_on_failure=false if you want to survive failures.

The SQL parser code in this method was taken from the SQL importer plugin (libraries/import/sql.php) from the phpMyAdmin Project and has been slightly modified to work in this context. Kudos to all people who wrote this code!

  • author: the phpMyAdmin developers
  • see: $this->_db
  • see: dbc::$sql_error
  • access: public
bool sql_script (string $file, [bool $die_on_failure = true])
  • string $file
  • bool $die_on_failure

Inherited Methods

Inherited From gui

 gui::__construct()
 gui::append()
 gui::assign()
 gui::debug()
 gui::display()
 gui::get_microtime()
 gui::get_template_vars()
 gui::get_themes()
 gui::register_object()
 gui::set_default_theme()

Inherited From session

 session::__construct()
 session::sess_destroy()
 session::sess_exists()
 session::sess_get_var()
 session::sess_store_var()
 session::sess_unset_var()

Documentation generated on Sun, 22 Aug 2010 11:20:17 +0200 by phpDocumentor 1.4.3