Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter CLI returns blank when utilizing a model


I am a newbie on this forum but almost always I do find my answers on this forum regarding CI except the following...

I am working on a project which is developed on CI 3.1.11 and I have to create some cli procedures that will later work on scheduled tasks (cron). However, when I run a function as simple as the following from CLI I do not get any return to my screen when I make a call to the model.

The code I am running is that simple...

PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
     class Cli extends CI_Controller
          public function check_expired()
            if(!$this->input->is_cli_request()) { echo "Not Allowed!"; return; }

            $t $this->db->get('requests');
            echo "C";

            echo "D";

my DB configuration is...

PHP Code:
$active_group 'default';
$query_builder TRUE;

$db['default'] = array(
'dsn' => '',
'hostname' => 'hmm.aha.com:3306',
'username' => 'shhh',
'password' => '[email protected]',
'database' => 'mydb',
'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['db2'] = $db['default'];
$db['db2']['database'] = "mydb2";

if (
module_exists('plans')) {
$db['db3'] = $db['default'];
$db['db3']['database'] = "mydb3";

my autoloaded libraries are...

PHP Code:
You can also supply an alternative library name to be assigned
in the controller:
$autoload['libraries'] = array('user_agent' => 'ua');
$autoload['libraries'] = array('database','session','lib_filter','simple_html_dom'); 

The "C" is echoed on the terminal but the "D" is not and of course when I tried to manipulate some records on the model the function just didn't touch them nor I got any kind of message on the codeigniter logs.

I must add that my environment is based on a debian docker and that I am running this command from interactive bash with root privileges (docker exec -it container_name bash).

If anyone has some kind of idea or lead I would be grateful to know it.

Thanks in advance!

Have you changed log mode in Codeigniter?
Have you checked your PHP error logs, depending on the crash it won't be visible in your CI logs.

(01-16-2020, 11:55 AM)jreklund Wrote: Have you changed log mode in Codeigniter?
Have you checked your PHP error logs, depending on the crash it won't be visible in your CI logs.

I did check that I have "display_errors = on" on php.ini and that I also have set a valid error log path with correct permissions...
I'm afraid that nothing is displayed not there nor in my STDOUT.

There must be something specific with my project since I've made the same test on a local debian box with php 7.3 and apache server and had exactly the same problem.

The funny thing is that through web it works fine in both situations (Docker and PC)!

I am out of ideas.

I just found the source of my problem...

as it is proposed here...


I am working on a development environment and I am working with the /application/config/development/database.php configuration file instead of the /application/config/database.php that the production environment uses.

the files are identical only the hostname, username and password entries are different.

However, if I copy the /application/config/development/database.php to the /application/config/ folder and replace the production database.php the function works as it should be from CLI.

Do you get anything from this?

Found the answer on that too.

The ENVIROMENT comes from an Apache variable, since I call the command from CLI it doesn't recognize the Apache environment variable hence it tries to connect to the production DB and get the records. He finds nothing and there is the problem.

If that is the case...
a. do you have any good idea how to pass through CLI that I am on a develoment environment?
b. why it didn't return any errors? (That is something that I do not care at the moment, just to be honest)

Evidently, I just exported the same CI_ENV variable with Apache on my .profile and everything works as it should be.

So you can wipe out a.

Thanks for your time, I hope this thread might help someone else, if not you can clear it.

I'm afraid I can't answer that one. Can be multiple things that suppress them. If you are using PHP-FPM they are forwarded into Apache error log for example.

Thanks for commenting on your findings, it will hopefully be able to assist someone else in the future!

Theme © iAndrew 2016 - Forum software by © MyBB