Welcome Guest, Not a member yet? Register   Sign In
CLI and database connectivity.
#1

[eluser]Joe_Archer[/eluser]
I have a very simple script which I intended to to call via the command line.
It utilises 2 databases, one MySQL and one which is connected over ODBC. when calling the method via a browser, it functions exactly as intended. However when I attempt to call the method via the CLI I get an error returned:
<p>Unable to connect to your database server using the provided settings.</p>
<p>Filename: <path to file>DB_driver.php</p>
<p>Line Number: 124</p>

Here is the database config:
$db['default']['hostname'] = 'DSN';
$db['default']['username'] = 'joe';
$db['default']['password'] = '';
$db['default']['database'] = 'timing';
$db['default']['dbdriver'] = 'odbc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

$db['my']['hostname'] = '127.0.0.1';
$db['my']['username'] = 'root';
$db['my']['password'] = '';
$db['my']['database'] = 'timing';
$db['my']['dbdriver'] = 'mysql';
$db['my']['dbprefix'] = '';
$db['my']['pconnect'] = TRUE;
$db['my']['db_debug'] = TRUE;
$db['my']['cache_on'] = FALSE;
$db['my']['cachedir'] = '';
$db['my']['char_set'] = 'utf8';
$db['my']['dbcollat'] = 'utf8_general_ci';
$db['my']['swap_pre'] = '';
$db['my']['autoinit'] = TRUE;
$db['my']['stricton'] = FALSE;

here is the controller:


public function index()
{
$this->load->database();
$DB2 = $this->load->database('my', TRUE);
$DB2->query("TRUNCATE TABLE drivers");
$query = "SELECT * FROM Drivers";
$result = $this->db->query($query);
$DB2->insert_batch('drivers', $result->result_array());

}

Any ideas why the database connection would fail over CLI but not the browser?
#2

[eluser]Pert[/eluser]
Is it the local DB or remote DB or both that fail to connect?
#3

[eluser]Joe_Archer[/eluser]
Both databases are local, it is the ODBC connection which fails. The hostname on the ODBC config is set to the DSN for the connection as this is required for the connection to function.
#4

[eluser]Pert[/eluser]
Might be worth checking if PHP actually loads ODBC libraries when called on command line?
#5

[eluser]Joe_Archer[/eluser]
ODBC functions on the command line perfectly in PHP I have used it many times outside of codeigniter.




Theme © iAndrew 2016 - Forum software by © MyBB