-
Notifications
You must be signed in to change notification settings - Fork 0
Database Layer
Available methods:
- changeDatabase
- isConnected
- query
- getOne
- getRow
- getCol
- getAll
- lastInsertID
- affectedRows
- free
- disconnect
- vardump
- debug
bool $this->db->changeDatabase(str $database)
Change the current connected database.
- database - Name of database to change connection to .
Returns TRUE if was successfully able to switch databases. Echoes an error if unable to switch databases.
<?php
$aData = $this->db->getAll("SELECT * FROM `table`");
$this->db->changeDatabase("database2");
$aMoreData = $this->db->getAll("SELECT * FROM `table2`");bool $this->db->isConnected()
Check to see if the database is connected. Good way of checking if database is in use.
Returns TRUE if the a connection to the database exists and a database is selected. Returns FALSE if no connection to the database or no database selected.
<?php
if($this->db->isConnected()) {
$aData = $this->db->getAll("SELECT * FROM `table`");
} else {
$aData = array();
}bool $this->db->query(str $query)
Used to run query on the database that does not expect data back. If data is returned, it's saved and accessible from getOne, getRow, getCol, getAll without passing a query.
- query - SQL query to pass to the database.
Returns TRUE if data was returned. Returns FALSE if no connection was found or if no data returned.
<?php
$this->db->query("SELECT * FROM `table`");
$aData = $this->db->getAll(null);string $this->db->getOne(str $query [, int $colOffset [, int $rowOffset]])
Get the first column of the first row unless changed by offsets.
- query - SQL query to pass to the database.
- colOffset - Change the column of the value returned starting with 0. Default is 0.
- rowOffset - Change the row of the value returned starting with 0. Default is 0.
Return INTEGER if a value exists for the column and row offsets of the returned results. Return FALSE if no connection was found.
<?php
$sID = $this->db->getOne("SELECT `id` FROM `table` LIMIT 1");array $this->db->getRow(str $query [, int $rowOffset [, str $fetchMode]])
Gets only the first row of data returned ob the database results unless changed by the offset.
- query - SQL query to pass to the database.
- rowOffset - Change the row of the value returned starting with 0. Default is 0.
- fetchMode - Changes how the data is returned. (object, assoc, ordered)
Returns ARRAY if a row exists in the row offset. Returns FALSE if no connection was found.
<?php
$aData = $this->db->getRow("SELECT `id`, `name`, `email` FROM `table` LIMIT 1");array $this->db->getCol(tr $query [, int $colOffset])
Get the column specified in the offset of the database results.
- query - SQL query to pass to the database.
- colOffset - Change the column of the value returned starting with 0. Default is 0.
Returns ARRAY if a column exists in the column offset. Returns FALSE if no connection was found.
<?php
$aData = $this->db->getCol("SELECT `id` FROM `table`");array $this->db->getAll(str $query [, str $fetchMode])
Fetch all data given back from the database.
- query - SQL query to pass to the database.
- fetchMode - Changes how the data is returned. (object, assoc, ordered)
Returns ARRAY if any data is returned by the database. Returns FALSE if no connection was found.
<?php
$aData = $this->db->getAll("SELECT `id`, `name`, `email` FROM `table`");integer $this->db->lastInsertID()
Gets the last AUTO_INCREMENT id created from the current connection.
Returns INTEGER of ID that is returned from the database. Returns FALSE if no connection was found.
<?php
$this->db->query("INSERT INTO `table` SET `name` = 'Test', `email` = 'john.doe@gmail.com'");
$sID = $this->db->lastInsertID();integer $this->db->affectedRows()
Gets the number of rows affected by the last query. Does not return any table relationship changes.
Returns INTEGER of number of rows affected. Returns FALSE if no connection was found.
<?php
$this->db->query("DELETE FROM `table` WHERE `id` > 0");
$sRows = $this->db->affectedRows();void $this->db->free()
Frees information of last query and any saved results.
<?php
$this->db->free();void $this->db->disconnect()
Closes connection to the database.
<?php
$this->db->disconnect();string $this->db->vardump(mixed $variable)
Displays information about last query along with any results that where returned. Also will PRINT_R the variable passed in.
- variable - Pass extra data you would like displayed along with last query info.
<?php
$this->db->vardump(array("key"=>"value"));string $this->db->debug()
Displays last SQL query and it's data in a table.
<?php
$this->db->debug();