$this->secondDB = $this->load->database($dbInfo, TRUE);
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "dbuser1";
$db['default']['password'] = "dbpass1";
$db['default']['database'] = "db1";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
// db for snagging the retailers info
$db['secondary']['hostname'] = "localhost";
$db['secondary']['username'] = "dbuser2";
$db['secondary']['password'] = "dbpass2";
$db['secondary']['database'] = "db2";
$db['secondary']['dbdriver'] = "mysql";
$db['secondary']['dbprefix'] = "";
$db['secondary']['pconnect'] = TRUE;
$db['secondary']['db_debug'] = TRUE;
$db['secondary']['cache_on'] = FALSE;
$db['secondary']['cachedir'] = "";
$db['secondary']['char_set'] = "utf8";
$db['secondary']['dbcollat'] = "utf8_general_ci";
class Retailers_model extends Base_module_model {
function __construct()
{
parent::__construct('retailers'); // table name
}
/*
need to use a basic query in a function rather than
retailers_model->find_one_by_id($id) in the view because we are
connecting to the other site's db. (I'm calling this from the view -
I'm sure there's a cleaner way to do it but I was in a hurry and feeling lazy)
*/
function get_retailer($id)
{
$db = $this->load->database('secondary', TRUE, TRUE);
$query = $db->query("
SELECT * FROM retailers
WHERE id=$id
");
$rows = $query->result_array();
return $rows[0];
}
// this is a function to pull in a google map if you're interested
function find_retailers($lat, $lng, $dist)
{
$db = $this->load->database('secondary', TRUE, TRUE);
$query = $db->query("
SELECT id, name, address, city, state, zipcode, phone, lat, lng,
( 3959 * acos( cos( radians( $lat ) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians( $lng ) ) + sin( radians( $lat ) ) * sin( radians( lat ) ) ) )
AS distance
FROM retailers
HAVING distance <$dist
ORDER BY distance
LIMIT 0 , 10
");
$data = $query->result_array();
return $data;
}
// more functions here
}
It looks like you're new here. If you want to get involved, click one of these buttons!