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
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
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'walkmjcd_moneywk',
'password' => 'q?P?Lf817H~y',
'database' => 'walkmjcd_walkmoney',
'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['default']='';
An Error Was Encountered You have not selected a database type to connect to. Please ANyone help in this case How can i resolve this.
The problem is, the db configuration you set at top and reset it at the bottom. Just remove the $db['default']=''; and try.
Please remove :
$db['default']='';
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => 'tes',
'hostname' => 'localhost',
'username' => '',
'password' => '',
'database' => 'tes',
'dbdriver' => 'odbc',
'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
);
When I run the program there is an error:
" Message: Call to undefined method CI_DB_odbc_driver::select() Filename: models/m_city.php"
m_city.php file:
<?php
class m_city extends CI_Model
{
function get_all($where = array())
{
$this->db->select('Name,Population');
$this->db->where($where);
$this->db->limit('50');
$query = $this->db->get('City');
return $query->result_array();
}
}
I already made dsn name on odbc. the name of dsn is "tes".
If you use "Mysql" then follow the following instructions.
Please put database username and database password in the following:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => '',//Put database username
'password' => '',// put database password
'database' => 'tes',
'dbdriver' => 'odbc',
'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
);
After complete this save the page and open the page 'autoload.php' under the config folder. There search "$autoload['libraries']" option. Put the following
$autoload['libraries'] = array('database');
If you use PDO, PostgreSQL, Oracle then see the following links:
https://www.codeigniter.com/user_guide/database/configuration.html
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!