codeigniter


add second database connection


I try to add a second database connection in my CI Application. The first is initialized by:
$autoload['libraries'] = array('database', 'session');
How can I access now a second database connection in my model? I tried this:
class Configurator_model extends CI_Model{
private $db2 = null;
function __construct()
{
parent::__construct();
$this->db2 = $this->load->database('configurator', TRUE);
}
public function all(){
$query = $this->db2->get('projects');
var_dump($query);
if($query->num_rows()>0){
return $query->result_array();
}
}
}
but there are no results. Var_dump returns:
object(CI_DB_mysql_result)#22 (8) { ["conn_id"]=> resource(47) of type (mysql link persistent) ["result_id"]=> resource(48) of type (mysql result) ["result_array"]=> array(0) { } ["result_object"]=> array(0) { } ["custom_result_object"]=> array(0) { } ["current_row"]=> int(0) ["num_rows"]=> int(0) ["row_data"]=> NULL }
The database is configured like this in the config:
...
$db['configurator']['hostname'] ...
...
I see this on CodeIgniter Userguide Hope this help.
$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = "mydatabase";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$this->load->model('Model_name', '', $config);
You can save the database in an element of the $cconfig variable like `$config['second_db'] and load this config in your controller.
Check out COnnecting to Multiple Databases: http://ellislab.com/codeigniter/user-guide/database/connecting.html

Related Links

Codeigniter google-url-master library
default controller not routing to my selected controller
Does codeigniter 3 support PHP 7?
API to get course category in moodle
Create pdf having each page background in different color using DOMPDF
image not storing in folder using codeigniter
Dynamically inserted textbox values to be stored in a variable
using mysqli driver in ci
Send sms using twilio and codeigniter
$_FILES['imagem'] is undefined in Firefox
CodeIgniter accessing models from helper
How to reuse form in codeigniter for update and add
How enable mbstring in codeigniter
make looping insert database from codeigniter
CodeIgniter URL: web.com/user/register/step/1
How can give name for generate pdf using mpdf codeigniter

Categories

HOME
codeigniter
ffmpeg
identityserver4
hortonworks-data-platform
auth0
openshift-origin
graylog2
redhat
ionic3
sony-camera-api
activerecord
proftpd
aac
chart.js2
editor
jquery-jtable
calabash-android
jsqmessagesviewcontroller
plc
w2ui
spring-boot-admin
atmelstudio
pywin32
nsmutableattributedstring
smartcard
sfsafariviewcontroller
many-to-many
nested-set-model
esri
android-security
flatbuffers
launchpad
monads
matterjs
machine-language
nib
edit-distance
bcel
executorservice
draggable
vtable
jsonstore
azure-management-api
nomenclature
logicblox
linear
syncfusion
spring-form
fasta
reactivex
jahia
javascript-security
masspay
shift-reduce-conflict
android-alertdialog
vistadb
hard-drive-failure
perspective
amazon-dynamodb-streams
cglib
groups
uploadify
pypdf
ssha
aldryn
coldfusion-10
tun
quasar
user-registration
base-conversion
pencilblue
generalization
openxls
android-tablelayout
populate
css3pie
lightstreamer
notifyicon
couchrest
execcommand
deap
buildout
glulookat
gora
webcal
chromeless
tempo
java-ee-5
jmdns
cloud-hosting
applaud
ariatemplates
android-actionmode
ria
ccr
noindex
quilt
b-method
boost-gil
emacs-ecb
jquery-pagination
jdic
custom-tag
jboss-cache
unitils
non-relational-database
development-machine

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App