Skip to content
defvayne23 edited this page Jan 4, 2012 · 1 revision

Available methods:

changeDatabase

Description

bool $this->db->changeDatabase(str $database)

Change the current connected database.

Parameters

  • database - Name of database to change connection to .

Return Values

Returns TRUE if was successfully able to switch databases. Echoes an error if unable to switch databases.

Example

  <?php
  $aData = $this->db->getAll("SELECT * FROM `table`");
  
  $this->db->changeDatabase("database2");
  
  $aMoreData = $this->db->getAll("SELECT * FROM `table2`");

isConnected

Description

bool $this->db->isConnected()

Check to see if the database is connected. Good way of checking if database is in use.

Return Values

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.

Example

  <?php
  if($this->db->isConnected()) {
      $aData = $this->db->getAll("SELECT * FROM `table`");
  } else {
      $aData = array();
  }

query

Description

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.

Parameters

  • query - SQL query to pass to the database.

Return Values

Returns TRUE if data was returned. Returns FALSE if no connection was found or if no data returned.

Example

  <?php
  $this->db->query("SELECT * FROM `table`");
  $aData = $this->db->getAll(null);

getOne

Description

string $this->db->getOne(str $query [, int $colOffset [, int $rowOffset]])

Get the first column of the first row unless changed by offsets.

Parameters

  • 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 Values

Return INTEGER if a value exists for the column and row offsets of the returned results. Return FALSE if no connection was found.

Example

  <?php
  $sID = $this->db->getOne("SELECT `id` FROM `table` LIMIT 1");

getRow

Description

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.

Parameters

  • 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)

Return Values

Returns ARRAY if a row exists in the row offset. Returns FALSE if no connection was found.

Example

  <?php
  $aData = $this->db->getRow("SELECT `id`, `name`, `email` FROM `table` LIMIT 1");

getCol

Description

array $this->db->getCol(tr $query [, int $colOffset])

Get the column specified in the offset of the database results.

Parameters

  • query - SQL query to pass to the database.
  • colOffset - Change the column of the value returned starting with 0. Default is 0.

Return Values

Returns ARRAY if a column exists in the column offset. Returns FALSE if no connection was found.

Example

  <?php
  $aData = $this->db->getCol("SELECT `id` FROM `table`");

getAll

Description

array $this->db->getAll(str $query [, str $fetchMode])

Fetch all data given back from the database.

Parameters

  • query - SQL query to pass to the database.
  • fetchMode - Changes how the data is returned. (object, assoc, ordered)

Return Values

Returns ARRAY if any data is returned by the database. Returns FALSE if no connection was found.

Example

  <?php
  $aData = $this->db->getAll("SELECT `id`, `name`, `email` FROM `table`");

lastInsertID

Description

integer $this->db->lastInsertID()

Gets the last AUTO_INCREMENT id created from the current connection.

Return Values

Returns INTEGER of ID that is returned from the database. Returns FALSE if no connection was found.

Example

  <?php
  $this->db->query("INSERT INTO `table` SET `name` = 'Test', `email` = 'john.doe@gmail.com'");
  $sID = $this->db->lastInsertID();

affectedRows

Description

integer $this->db->affectedRows()

Gets the number of rows affected by the last query. Does not return any table relationship changes.

Return Values

Returns INTEGER of number of rows affected. Returns FALSE if no connection was found.

Example

  <?php
  $this->db->query("DELETE FROM `table` WHERE `id` > 0");
  $sRows = $this->db->affectedRows();

free

Description

void $this->db->free()

Frees information of last query and any saved results.

Example

  <?php
  $this->db->free();

disconnect

Description

void $this->db->disconnect()

Closes connection to the database.

Example

  <?php
  $this->db->disconnect();

vardump

Description

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.

Parameters

  • variable - Pass extra data you would like displayed along with last query info.

Example

  <?php
  $this->db->vardump(array("key"=>"value"));

debug

Description

string $this->db->debug()

Displays last SQL query and it's data in a table.

Example

  <?php
  $this->db->debug();

Clone this wiki locally