Firebird is a relational database management system (RDBM) open sourced by Borland.
Firebird with PostgreSQL and
MySQL is one of the best-known open source databases.
Requirements
Kumbia Enterprise uses php extensions "interbase" and "pdo_firebird" to connect to Firebird / Interbase
using the native layer, so it is necessary that any of these 2 extensions are available.
You can make connections to Firebird / Interbase databases using TCP/IP or IPX protocols.
The databases can be deployed on the same server or as a remote resource. To configure the
database in environment.ini use the following configuration:
Firebird adapter has been implemented throughout the Db component API, so naturally
you can use all its functionality:
//Do a Query
$db->query("SELECT * FROM customers");
$numberRows = $db->numRows();
//If there are rows then show it
if($numberRows>0){
while($customer = $db->fetchArray()){
echo $customer[0], "\n";
echo $customer["name"], "\n";
}
}
//Show the second customer
$db->dataSeek(1);
$row = $db->fetchArray();
echo $row["name"], "\n";
//"customers" table exists?
$db->tableExists("customers");
//List all the database tables
$tables = $db->listTables();
foreach($tables as $table){
echo $table, "\n";
}
//Query all table meta-data
$fields = $db->describeTable("customers");
foreach($fields as $field){
print_r($field);
}
LIMIT Implementation
As with the other adapters Db, Firebird adapter has been implemented the SQL language extension
called LIMIT that allows to define the number of records returned by the database in a single query:
//Do a Query
$sql = $db->limit("SELECT * FROM customers", 10);
$cursor = $db->query($sql);
$numberRows = $db->numRows($cursor); // 10
Firebird/Interbase do not support identity columns (auto numeric), instead it is
possible to use generators. A generator can be created using the usual convention for sequences
TABLE_FIELD_SEQ. If the primary key field called ID as well then the model can define as follows:
class Customers extends ActiveRecord {
}
If no primary key field called ID then we can define the generator as follows:
class Customers extends ActiveRecord {
public function initialize(){
$this->setIdGenerator("Native", "code");
}
}
If the generator has a different name to the convention you can
use a native generator to indicate your name:
class Customers extends ActiveRecord {
public function sequenceName(){
return "CUSTOMERS_CODE_GEN";
}
public function initialize(){
$this->setIdGenerator("Native", "code");
}
}
Then use the model as usual:
//Create a customer
$customer = new Customers();
$customer->name = "John Applesed";
$customer->created = new DbRawValue("CURRENT_TIMESTAMP"); #Set the database system date
$customer->save();
//Show the ID that was assigned to record from the generator (sequence)
echo $customer->id;
//Show the name of all customers
foreach(Customers::findAll() as $customer){
echo $customer->name, "\n";
}
Conclusions
Firebird is a powerful open source engine which can be exploited in Kumbia Enterprise
The complete functionality of Db and ActiveRecord components can be utilized with Firebird/Interbase databases
If you have problems using the Firebird/Interbase adapter, you can get support
from the framework developers in our discussion group on
google groups.
Tell friends about this article on social networks: