====== nsDatabase ======
This is MySQL database driver. Currently NickSoft Class Library supports only mysql.
===== Members =====
==== totalTime ====
public $totalTime = 0.0;
This is total time in seconds of all database queries. It is float value which contains microseconds info too.
==== timeStart ====
public $timeStart = 0.0;
This is the time since MySQL connection was open.
==== lastQuery ====
public $lastQuery;
This is the last query executed.
==== dbLink ====
protected $dbLink = null;
This is MySQL database link resource. It can be set using [[#import]] method
===== Methods =====
==== Constructor ====
public function __construct($dbHost,$dbName,$dbUser,$dbPass);
Constructor. Sets credentials. Note that connection is not opened on object creation.
FIXME - credentials need to be passed as array;
==== connect ====
* **return value:** link id resource
public function connect();
==== import ====
* $link - MySQL link id resource
* $dbName - Database name
* **return value:** -
public function import($link, $dbName = false);
Imports a link id resourse.
Note that reconnecting will not work if credentials are not correct.
==== selectDb ====
* $dbName - Database name
* **return value:** -
public function selectDb($dbName);
If not successful an exception is thrown.
==== setOptions ====
* $dbFlags - flags.
* **return value:** -
public function setOptions($dbFlags);
Accepted flags are:
* **MYSQL_CLIENT_SSL** - use ssl connection
* **MYSQL_CLIENT_COMPRESS** - use compression
* **MYSQL_CLIENT_IGNORE_SPACE** - :?:
* **MYSQL_CLIENT_INTERACTIVE** - :?:
==== escape ====
* $str - string to escape.
* **return value** - escaped string
public function escape($str);
Escape a string to use as value in MySQL connection. It uses **mysql_real_escape_string()** and takes connection information in account
==== quote ====
Synonym for [[#escape]]
==== foundRows ====
* **return value** - number of rows without LIMIT
public function foundRows();
Returns number of rows that would have returned previous SELECT query if there was not LIMIT clause. To work this previous SELECT query must contain SQL_CALC_FOUND_ROWS directive.
==== query ====
* $query - the query to run.
* **return value** - mysql result resource
public function query($query);
Runs query and returns result resource. In case of error an exception is thrown.
==== queryFirstField ====
* $query - the query to run.
* **return value** - value of first field of first row of the result
public function queryFirstRow($query);
Runs query and returns value of first field of first row of the result. In case of error an exception is thrown.
==== queryFirstRow ====
* $query - the query to run.
* $fetchFunc - type of array - MYSQL_ASSOC or MYSQL_NUM.
* **return value** - array of values in first row
public function query($query, $fetchFunc = MYSQL_ASSOC);
Runs query and returns array of values of the first row in the result. If $fetchFunc is MYSQL_ASSOC array is associative using column names as keys.
In case of error an exception is thrown.
==== queryRows ====
* $query - the query to run.
* $fetchFunc - type of array - MYSQL_ASSOC or MYSQL_NUM.
* **return value** - all rows in the result as array of arrays.
public function query($query, $fetchFunc = MYSQL_ASSOC);
Runs query and returns rows of result as array of arrays. If $fetchFunc is MYSQL_ASSOC array is associative using column names as keys.
In case of error an exception is thrown.
==== queryAssoc ====
* $query - the query to run.
* $key - Key field for associative array.
* $value - Value field for associative array.
* **return value** - associative array with results.
public function queryAssoc($query, $key, $value);
Returns associative array where key is value of $key field and value id value of $value field. Good for