We are doing a small custom plugin that needs to query an outside MySQL database. Assuming it is possible, how would I create a connection to this database using the standard EE or CI system?
I am thinking this should be as simple as loading the DB class, creating a new instance with the connection credentials for the outside database.
Some pointers in how to set this up would be really appreciated.
Given time anything is possible. This is what I did in the end. If there is a “more” proper way to do this, please let me know:
require_once ( PATH_THIRD . 'phpbb_custom_feeds/config.php');
$phpbb_db = $this->EE->load->database($db_phpbb, TRUE);config.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$db_phpbb = array();
$db_phpbb['hostname'] = "localhost";
$db_phpbb['username'] = "my_username";
$db_phpbb['password'] = "my_password";
$db_phpbb['database'] = "my_database";
$db_phpbb['dbdriver'] = "mysql";
$db_phpbb['dbprefix'] = "";
$db_phpbb['pconnect'] = FALSE;
$db_phpbb['db_debug'] = FALSE;
$db_phpbb['cache_on'] = FALSE;
$db_phpbb['cachedir'] = "";
$db_phpbb['char_set'] = "utf8";
$db_phpbb['dbcollat'] = "utf8_general_ci";
$db_phpbb['swap_pre'] = "";
$db_phpbb['autoinit'] = TRUE;
... additional configuration ...I was then able to use active record queries to get what I need.
$phpbb_db->select('forum_id');
$phpbb_db->where('parent_id', $my_id);
$query = $phpbb_db->get('phpbb_forums');Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.