Welcome Guest, Not a member yet? Register   Sign In
Codeigniter CLI mode calling firebird database
#1
Photo 

Guys,

I am building an application where I have to retrieve data from firebird database and then insert it into mysql database. Thus, I defined the following databases in the config/database.php 

Code:
$db['default'] = array(
    'dsn'    => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'eStockCard',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

$db['FINA'] = array(
    'dsn'    => '',
    'hostname' => 'localhost',
    'username' => 'SYSDBA',
    'password' => 'masterkey',
    'database' => 'C:\Users\Teddy Djohan\Documents\SSM\InventoryModule\PT. SINAR SAKTI METALINDO.FDB',
    'dbdriver' => 'ibase',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

Then, in my controller item_fina.php, I code it like this:
Code:
<?php
class Item_Fina extends MY_Controller
{
   public function __construct()
   {
       parent::__construct();
       $this->load->model('item_master_xref_model', 'item_master_xref');
       $this->load->model('item_fina_balance_model', 'item_fina_balance');
       $this->load->model('item_fina_model', 'item_fina');
   }


   public function index()
   {

       // Get Item Code Xref between eStockCard and FINA
       $item_master_xref = $this->item_master_xref->get_all_itemcode();

       // Delete all rows with the same item_code from item_fina_balance table
       foreach ($item_master_xref as $row) {
         $item_code[] = $row['item_code_external'];
       }

       $this->item_fina_balance->hapus($item_code);

       $CurrentDate = date("Y-m-d");
       $warehouse = 0;

       foreach ($item_master_xref as $row) {

           // Get the item balance quantity from FINA
           $item_code_external = $row['item_code_external'];
           $itemqtyfromfina = $this->item_fina->getitembywh($CurrentDate, $item_code_external, $warehouse);
           
           $itemfinabal['itemno'] = $itemqtyfromfina['ITEMNOWH'];
           $itemfinabal['quantity'] = $itemqtyfromfina['QUANTITY'];
           $itemfinabal['date'] = $CurrentDate;
           $this->item_fina_balance->tambah($itemfinabal);
       }

   }
}

There is three models involved in this controller:
  1. item_master_xref_model ------> using 'default' database which is MySQL
  2. item_fina_balance_model ------> using 'default' database which is MySQL
  3. item_fina_model ------> using 'FINA' database which is Firebird
I have no issues with the 'default' database (MySQL). Thus, I will just show the snippets model code of item_fina_model below:
Code:
<?php
class Item_Fina_Model extends CI_Model
{


    // Nama tabel database yang akan digunakan.
   protected $_tabel = 'ITEM';
clear
   protected $db_fina;

   public function __construct()
   {
       parent::__construct();

       $CI = &get_instance();
       $this->db_fina = $CI->load->database('FINA', TRUE);
       
   }

When I run the controller through a browser (URL), everything works fine. It grabs the data from Firebird database and then insert into MySQL database. However, I need to run this controller through CLI as a scheduled task daily.
When I run this controller through CLI using Command Prompt in windows, I keep getting this error:

Code:
C:\xampp\htdocs\eStockCard>php index.php item_fina index
PHP Fatal error:  Call to undefined function ibase_connect() in C:\xampp\htdocs\eStockCard\system\database\drivers\ibase\ibase_driver.php on line 90

Fatal error: Call to undefined function ibase_connect() in C:\xampp\htdocs\eStockCard\system\database\drivers\ibase\ibase_driver.php on line 90

A PHP Error was encountered

Severity:    Error
Message:     Call to undefined function ibase_connect()
Filename:    C:\xampp\htdocs\eStockCard\system\database\drivers\ibase\ibase_driver.php
Line Number: 90

Backtrace:


It is as if the php_interbase.dll or fbclient.dll for Firebird database is not loaded at all. It is working fine though when called from the browser (URL). 

Can anyone help me on this issue? Thank you very much.



Teddy Djohan
Reply
#2

(This post was last modified: 03-29-2016, 03:05 AM by orionstar.)

How do you call php from CLI? Exactly what command did you run?

I think you have more thane one php version installed and the CLI one is different than you use with your web server. If my assumption is true, then you have to enable interbase extensions in all php version's php.ini...

Run get_loaded_extensions() (http://php.net/manual/en/function.get-lo...nsions.php) to check interbase is loaded.
Reply
#3

(03-29-2016, 03:05 AM)orionstar Wrote: How do you call php from CLI? Exactly what command did you run?

I think you have more thane one php version installed and the CLI one is different than you use with your web server. If my assumption is true, then you have to enable interbase extensions in all php version's php.ini...

Run get_loaded_extensions() (http://php.net/manual/en/function.get-lo...nsions.php) to check interbase is loaded.

orionstar,

You are right on spot on this issue. I never realize that I have another PHP installation in my machine and the PATH variable in windows environment is pointing to that PHP installation. Once I change the PATH variable to point to the PHP in the XAMPP folder, it works successfully.

Thank you very much.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB