Jump to content
DevFuse Forums
Sign in to follow this  

[IPB 3.0.x] Database Queries


Description

A few basic examples of IPB built in database class.
IP.Board 3.30.x comes with a built in database class. This will perform just about any database query you may have. Below are some of the basics.

Database Select
[code]$this->DB->build( array( 'select' => '*', 'from' => 'db_table' ) );
$this->DB->execute();
$r = $this->DB->fetch();[/code]

Database Insert
[code]$this->DB->insert( 'db_table', array ( 'row1' => "row1", 'row2' => "row2", 'row3' => "row3", ) );[/code]

Database Delete
[code]$this->DB->delete( 'db_table', 'id=1' );[/code]

You can also add different code to your query, including where, order and limit.

Where
[code]'where' => 'id=1'[/code]

Order
[code]'order' => 'date DESC'[/code]

Limit
[code]'limit' => array(0,1)[/code]

Some areas of IP.Board 3 may require you to setup the DB object at the construct like so.

[code]$this->DB = $this->registry->DB();[/code]


Recommended Comments

There are no comments to display.

×
×
  • Create New...