PHP + ADOdb + Firebird

Friday, July 4th, 2008

Here we go…

First download the latest PHP ADOdb library here: ADOdb Library for PHP.

Install it in proper directories and make sure your Firebird server is running.

- Setup your PHP to support Firebird functions

Edit your php.ini and do this:

  • setup YOUR extension_dir
    extension_dir = “D:\PHP5\ext”
  • Remove the ; of the interbase library
    ;extension=php_ifx.dll
    ;extension=php_imap.dll
    extension=php_interbase.dll
    ;extension=php_ldap.dll
    ;extension=php_mcrypt.dll
    ;extension=php_mhash.dll
  • restart your apache or IIS or whatever

- Setup the database info
<?php
define("DBUSER", "sysdba");
define("DBPASS", "foopassword");
define("DBHOST", 'localhost:C:/your/path/to/the/database.gdb');
?>

!POSSIBLE PROBLEM!: in the host parameter, localhost must be the IP address or hostname of the server where is running the Firebird server.

- Setup the ADOdb
<?php
include("adodb/adodb.inc.php");
// VERY IMPORTANT due Firebird do not send the column names as default
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$DB = &ADONewConnection(’firebird’);
$DB->Connect(DBHOST, DBUSER, DBPASS);
?>

- Testing
<?php
$SQL = "SELECT * FROM TABLENAME ORDER BY DAMNFIREBIRD";
$res = $DB->Execute($SQL);
if ($res->RecordCount() != 0) {
  while(!$res->EOF) {
    echo $res->fields['DAMNFIREBIRD'];
    $res->MoveNext();
  }
}
?>

5° - this shit is working =)

LIMIT in SELECT for Firebird

Friday, July 4th, 2008

The Firebird equivalent for mySQL/PostgreSQL LIMIT statement is:

SELECT FIRST X [SKIP Y] * FROM …. (your query)

Simple, the X is the number of results you want and the Y is how many results you want to “jump”.
The SKIP is optional.
Example:

SELECT FIRST 20 SKIP 40 columnA, columnB FROM TABLENAME …

that’s it.