I have tried this to make local database connection. But it gives this error:
You have specified an invalid database connection group (ci_test) in your config/database.php file.
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost', // pass this
'username' => 'root', // pass this
'password' => '', // pass this
'database' => 'ci_test', // pass this
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array());
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost', //this will be same
'username' => 'root', //replace with your username
'password' => '', //replace with your password
'database' => 'test', //replace with your database name which you want to use
'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);
try this. good luck.
This error relates to the connection group, not the database name. The connection group you have specified there is default, as shown on the first line: $db['default'].
Look for:
$active_group = 'ci_test';
Replace it with:
$active_group = 'default';
There is more information in the codeigniter documentation.
You can try this solution for your problem.
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'root',
'database' => 'ci_test',
'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
);
I hope this will helps you. Thanks!
Related
what is way i can use to create a connection between codeigniter and sql server?
below is the way i was connecting but it seems not to work
$active_group = 'default'; $query_builder = TRUE; $db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'port' => '1433',
'username' => 'username',
'password' => '*****',
'database' => 'database_name',
'dbdriver' => 'mssql',
'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
);
the connection is not established and i cant figure out what is the problem
$active_group = 'default'; $query_builder = TRUE; $db['default'] = array(
'dsn' => '',
'hostname' => 'computer_name\SQLEXPRESS',
'port' => '1433',
'username' => 'username',
'password' => '*****',
'database' => 'database_name',
'dbdriver' => 'sqlsrv',
'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
);
First i needed to install the sql server php driver on my computer
installing the extension. download driver then extract then copy php_pdo_sqlsrv_72_nts_x64.dll, php_pdo_sqlsrv_72_ts_x64.dll, php_sqlsrv_72_nts_x64.dll, php_sqlsrv_72_ts_x64.dll to the /php/ext. then add these extension=php_pdo_sqlsrv_72_nts_x64.dll extension=php_pdo_sqlsrv_72_ts_x64.dll extension=php_sqlsrv_72_nts_x64.dll extension=php_sqlsrv_72_ts_x64.dll in /php/php.ini. restart apache
I just want to know how to make two active connections in CG(Database Config) one is Localhost the other one is web. I want to have two database connections for fail safe purpose.I have not try to code it yet but an Idea or a sample code will be a great help. (how to add webserver connection?)
here's the single connection(local):
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array('dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'projectbox_db',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'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' => array(),
'save_queries' => TRUE);
if(ENVIRONMENT == 'production') {
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array('dsn' => '',
'hostname' => 'localhost',
'username' => 'server_username',
'password' => 'server_password',
'database' => 'projectbox_db',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'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' => array(),
'save_queries' => TRUE);
} else {
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array('dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'projectbox_db',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'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' => array(),
'save_queries' => TRUE);
}
You have to change the environment, according to the local code and your production code
I'm new in CI,
can someone help ?
I have 2 database connections :
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => '10.1.0.166',
'username' => 'sa',
'password' => 'Sprite12345',
'database' => 'HRD',
'dbdriver' => 'sqlsrv',
'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['credit'] = array(
'dsn' => '',
'hostname' => '10.1.0.166',
'username' => 'sa',
'password' => 'Sprite12345',
'database' => 'BHAKTI',
'dbdriver' => 'sqlsrv',
'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
);
And now, I'm trying to change the database value of $db['credit'].
something like this :
$db2 = $this->load->database('credit', TRUE);
$db2->database = 'BIT';
echo $db2->database;
$db2 = $this->load->database('credit', TRUE);
$db2->select('*');
$db2->from('tblconfig');
$query = $db2->get()->result();
print_r($query);
But the query result still take the tblconfig from BHAKTI not from BIT.
How can I change the database value in the config/database.php ?
Thanks in advance.
I'm using Codeigniter and I can't connect my database, give me an error:
I just add the library in autoload.php :
`$autoload['libraries'] = array('database');`
and this are my settings in database.php
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'root',
'database' => 'heroes',
'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
);
:S any help?
Just I changed localhost by 127.0.0.1:3306
I am using this code in CodeIgniter to add a database:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '12345',
'database' => 'saas',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'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' => array(),
'save_queries' => TRUE
);
How can I add a second database?
And How can i use them simultaneously?
Any help would be greatly appreciated!
From The Documentation:
$db['test'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'database_name',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'compress' => FALSE,
'encrypt' => FALSE,
'stricton' => FALSE,
'failover' => array()
);
In your model you can write:
function method()
{
$test = $this->load->database('test', TRUE); // the TRUE paramater tells CI that you'd like to return the database object.
$query = $test->select('first_name, last_name')->get('person');
var_dump($query);
}
Read More (http://www.codeigniter.com/user_guide/database/configuration.html)