Posts: 21
Threads: 8
Joined: Mar 2016
Reputation:
0
Hi guys.
You can easily set up a connection to my database by database.php file. The problem is that when I try to configure more than one connection my application crashes. How do I configure multiple connections in database.php power and give a CRUD in Model.php?
Posts: 215
Threads: 16
Joined: Oct 2014
Reputation:
10
04-14-2016, 04:11 PM
(This post was last modified: 04-14-2016, 04:12 PM by spjonez.)
Connecting to Multiple Databases: https://codeigniter.com/user_guide/datab...cting.html
If you're autoloading you should specify the default and load the second one manually.
Posts: 21
Threads: 8
Joined: Mar 2016
Reputation:
0
(04-14-2016, 04:11 PM)spjonez Wrote: Connecting to Multiple Databases: https://codeigniter.com/user_guide/datab...cting.html
If you're autoloading you should specify the default and load the second one manually.
Can you give an example ?
Posts: 185
Threads: 7
Joined: Oct 2014
Reputation:
23
$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);
Posts: 21
Threads: 8
Joined: Mar 2016
Reputation:
0
04-19-2016, 05:42 PM
(This post was last modified: 04-19-2016, 05:47 PM by jocm.aguiar.)
(04-18-2016, 12:49 PM)dmyers Wrote: $DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);
I will detail my nonfunctional code?
» File Setup » database.php
$active_group = 'dbone';
$query_builder = TRUE;
$db['dbone'] = array(
'dsn' => '',
'hostname' => '000.000....',
'username' => '',
'password' => '',
'database' => '',
'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
);
//$active_group = 'dbtwo';
//$query_builder = TRUE;
$db['dbtwo'] = array(
'dsn' => '',
'hostname' => '000.000...',
'username' => '',
'password' => '',
'database' => '',
'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
);
File_model.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class File_model extends CI_Model {
public function insert() {
$dbs = $this->load->database('screens', TRUE);
$email = 'myemail';
$this->db->insert('ws_user_on', $$email);
}
}
I can not see error? And simply does not work?
Posts: 185
Threads: 7
Joined: Oct 2014
Reputation:
23
(04-19-2016, 05:42 PM)jocm.aguiar Wrote: (04-18-2016, 12:49 PM)dmyers Wrote: $DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);
I will detail my nonfunctional code?
» File Setup » database.php
$active_group = 'dbone';
$query_builder = TRUE;
$db['dbone'] = array(
'dsn' => '',
'hostname' => '000.000....',
'username' => '',
'password' => '',
'database' => '',
'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
);
//$active_group = 'dbtwo';
//$query_builder = TRUE;
$db['dbtwo'] = array(
'dsn' => '',
'hostname' => '000.000...',
'username' => '',
'password' => '',
'database' => '',
'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
);
File_model.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class File_model extends CI_Model {
public function insert() {
$dbs = $this->load->database('screens', TRUE);
$email = 'myemail';
$this->db->insert('ws_user_on', $$email);
}
}
I can not see error? And simply does not work?
1st: You selected a database config named 'screens'? but your database configs are dbone and dbtwo.
2nd: If 'screens' did exist you assigned it to a object $dbs BUT used the $this->db object? that would be $dbs-> insert('ws_user_on', $$email);
3rd: You tried to use a variable named myemail because you used a variable variable and myemail doesn't contain anything because it's not declared.
DMyers
Posts: 21
Threads: 8
Joined: Mar 2016
Reputation:
0
I made the settings as and did not work ?
Posts: 33
Threads: 13
Joined: Apr 2015
Reputation:
0
$this->one = $this->load->database('dbone', true);
$this->two = $this->load->database('dbtwo', true);
$this->one->select('*')->from('some_table')->get();
$this->two->query('select * from some_table');
|