connect to non C5 db
Permalink
I've found several examples of connecting to a separate database like at:
http://www.concrete5.org/documentation/introduction/database-access...
Not sure if it's my version for WS2008R2 PHP/v.5.5.12 C5 v.5.6.3.1 but this doesn't work. In concrete/core/libraries/loader.php is the fn sig
Maybe the $create arg is new. I was getting a 500 err until I added another boolean to the Loader:db call. Even doing that, all the args are ignored and the sql query is applied to the C5 db.
What does work is adding the dbname onto the query:
I'm calling this from a model and I tried to figure out why the args are ignored but couldn't really tell what was happening with db debugging on or logging vars to the dashboard, maybe the connection string is reset elsewhere. So what's the right way to do this?
http://www.concrete5.org/documentation/introduction/database-access...
$db = Loader::db( 'newserver', 'newuser', 'newpassword', 'newdatabase', true);
Not sure if it's my version for WS2008R2 PHP/v.5.5.12 C5 v.5.6.3.1 but this doesn't work. In concrete/core/libraries/loader.php is the fn sig
public static function db($server = null, $username = null, $password = null, $database = null, $create = false, $autoconnect = true) {
Maybe the $create arg is new. I was getting a 500 err until I added another boolean to the Loader:db call. Even doing that, all the args are ignored and the sql query is applied to the C5 db.
What does work is adding the dbname onto the query:
$db = Loader::db(DB_SERVER, DB_USERNAME, DB_PASSWORD, 'otherdb', false, true); $sql = 'SELECT * FROM `otherdb`.tablename'; $result = $db->Execute($sql);
I'm calling this from a model and I tried to figure out why the args are ignored but couldn't really tell what was happening with db debugging on or logging vars to the dashboard, maybe the connection string is reset elsewhere. So what's the right way to do this?