How can i connect sqlite3 with ci4?
my configurations are:
public $default = [
'DSN' => '',
'hostname' => '',
'username' => '',
'password' => '',
'database' => 'edmis.db',
'DBDriver' => 'SQLite3',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'cacheOn' => false,
'cacheDir' => '',
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 3306,
];
file edmis.db exist in folder 'writable'
Error i am receiving.
Related
I want to import data from other database with dynamic connection
in codeigniter user input the database credential in the form and than I want to connect that database and import some data in the primary database. the question is how to set the second database connection with the dynamic values.
this is your first db connection from application/config/database.php
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'first_db',
'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
);
and this is second db connection function from model or controller or helper your choice.
private function second_db(){
return $db['second'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'second_db',
'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
);
}
private function first_db(){
return $db['second'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'first_db',
'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
);
}
if you set up your settings then you can switch your database with this code
$this->load->database(first_db(), TRUE);
$this->load->database(second_db(), TRUE);
CodeIgniter\Database\Exceptions\DatabaseException #8
Unable to connect to the database. Main connection [MySQLi]: Access denied for user 'xxxx'#'localhost' (using password: YES)
I'm trying to access my program, but I can't connect the database. How do I do that? cause i'm still beginner
public $default = [
'DSN' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'starter',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'cacheOn' => false,
'cacheDir' => '',
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
// 'failover' => array(),
// 'save_queries'=> TRUE,
'port' => 3306,
];
public $tests = [
'DSN' => '',
'hostname' => '127.0.0.1',
'username' => 'root',
'password' => '',
'database' => ':memory:',
'DBDriver' => 'SQLite3',
'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production ),
'cacheOn' => false,
'cacheDir' => '',
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 3306,
];
I Developed Codeigniter app with SQL server connection. it is properly connected when using PHP 5.6 on windows 7 PC, but same application not working on windows 10 with same PHP version. showing the error
$db['default'] = array(
'dsn' => '',
'hostname' => '192.168.0.241',
'username' => 'sa',
'password' => 'mypw',
'database' => 'dbsrver',
'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
);
You might have some error in configuration. Make sure you have correctly configure database.
In application/config/databse.php
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'write password if any otherwise leave it empty',
'database' => 'Your_Database_Name',
'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
);
What is the purpose of using $db['read-write'] AND $db['read-write-create'] in database.php (application/config/database.php) in Codeigniter? Please help me to get an answer .
$db['read-write'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'root',
'database' => 'db_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
);
$db['read-write-create'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'root',
'database' => 'db_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 want connect to 3 databases. I don't have any problem if i connect just two databases. When i try to connect 3 databases. i have problem like i cant connect to database two.
this my config at database.php :
$db['default'] = array(
'dsn' => '',
'hostname' => '192.168.11.29,1433',
'username' => 'userhsp',
'password' => 'hsp432#',
'database' => 'HSP',
'dbdriver' => 'mssql',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => FALSE,
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
$db['crm'] = array(
'dsn' => '',
'hostname' => '192.168.11.29,1433',
'username' => 'userhsp',
'password' => 'hsp432#',
'database' => 'CRM',
'dbdriver' => 'mssql',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => FALSE,
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
$db['pltapol'] = array(
'dsn' => '',
'hostname' => '192.168.11.29,1433',
'username' => 'userhsp',
'password' => 'hsp432#',
'database' => 'pltapol',
'dbdriver' => 'mssql',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => FALSE,
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
and in my model like this :
private $db2;
private $db3;
public function __construct()
{
parent::__construct();
$this->db2 = $this->load->database('crm', TRUE);
$this->db3 = $this->load->database('pltapol', TRUE);
}
i just can get object from database pltapol, but i dont get object from crm. how to fix it?
I want to answer my question. i tried to use
$this->db2->db_select() or $this->db3->db_select()
if i want to use that connection before $this->db2->query() or before $this->db2->query()
that is work!
happy coding :)