CodeIgniter Forums

Full Version: MySQL Issues when running via CLI
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was trying to get some resources working via CLI, so I created a "cli_test" method inside the "Test" controller, which just outputs a string. When I execute it, I get a database error. Here is the output:
Quote:$ clear
MacBooks-MacBook-Air:htdocs me$ php index.php test cli_test
Xdebug requires Zend Engine API version 220121212.
The Zend Engine API version 220131226 which is installed, is newer.
Contact Derick Rethans at http://xdebug.org/docs/faq#api for a later version of Xdebug.

A PHP Error was encountered

Severity: WarningMessage:  mysqli::real_connect(): (HY000/2002): No such file or directoryFilename: /Users/me/PhpstormProjects/SOME-App/htdocs/system/database/drivers/mysqli/mysqli_driver.phpLine Number: 135

Backtrace:

File: /Users/me/PhpstormProjects/SOME-App/htdocs/application/controllers/Test.php Line: 12 Function: __construct

File: /Users/me/PhpstormProjects/SOME-App/htdocs/index.php Line: 292 Function: require_once

Database error: A Database Error Occurred

Unable to connect to your database server using the provided settings.
Filename: controllers/Test.php
Line Number: 12

Heres the MySQL config:
PHP Code:
$active_group 'development';

$query_builder TRUE;

$db['development'] = array(
 
   'dsn'        => '',
 
   'hostname'      => 'localhost',
 
   'username'      => 'root',
 
   'password'      => 'Password1',
 
   'database'      => 'sasset',
 
   'dbdriver'      => 'mysqli',
 
   'dbprefix'      => 'sassetdb_',
 
   'pconnect'      => FALSE,
 
   'db_debug'      => TRUE,
 
   'cache_on'      => FALSE,
 
   'cachedir'      => '',
 
   'char_set'      => 'utf8',
 
   'dbcollat'      => 'utf8_general_ci',
 
   'swap_pre'      => '',
 
   'encrypt'       => FALSE,
 
   'compress'      => FALSE,
 
   'stricton'      => FALSE,
 
   'failover'      => [],
 
   'save_queries'  => TRUE
); 

However whenever visit the page via the browser, it works perfectly fine..

I looked at line 135 in the mysqli_driver.php file, its
PHP Code:
return $mysqli->real_connect($hostname$this->username$this->password$this->database$port$socket$client_flags) ? $mysqli FALSE

Could it be the $socket?

Edit: When I output the socket, its empty/null, so I doubt thats it...
I tried a simple CLI call on another CI instance that I have running locally. When its not configured to use the database, it works fine, when I do have a database configured, it throws the error.

is there something special I need to do to get CI working with the DB on the command line?
I found it, looks like I had to specify the mysqli.default_socket in the php.ini