We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How do I create a DB connection for an outside DB from within a plugin?

Development and Programming

OutofControl's avatar
OutofControl
164 posts
15 years ago
OutofControl's avatar OutofControl

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.

       
OutofControl's avatar
OutofControl
164 posts
15 years ago
OutofControl's avatar OutofControl

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');
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.