Elxis CMS Forum

Support => Database => Topic started by: gsot on February 08, 2011, 12:35:39

Title: Connect on second database
Post by: gsot on February 08, 2011, 12:35:39
I want to make a call to a database other than Elxis. I took a look on this post https://forum.elxis.org/index.php?topic=3025.0 (https://forum.elxis.org/index.php?topic=3025.0).
The problem is that when I connect on the external db, using the $database object, I lose connection to the Elxis db. ???

$database2 = new database('localhost', 'user', 'pass', 'db', 'prefix', 'driver');
$database2->setQuery($sql);
$rows = $database2->loadObjectList();

I know that when making calls to a different database with mysql_connect()  you need to pass true for the new link (fourth) parameter, otherwise the same connection is reused.
example: $conn = mysql_connect('localhost', 'user', 'pass', true);

Which parameter does that in the $database object? If anyone has the answer, let me know. It would save me a lot of searching!!

P.S The following code works fine
Code: [Select]
$conn = mysql_connect('localhost', 'user', 'pass', true) or die('Σύνδεση αδύνατη: ' .
    mysql_error());
mysql_query("SET NAMES 'utf8'", $conn);
mysql_select_db('db',$conn);   
$query = mysql_query($sql,$conn_cat) or die(mysql_error());
Title: Re: Connect on second database
Post by: webgift on February 08, 2011, 14:10:04
If your second database is not Elxis' then you don't have to use the Elxis' database class. You can connect, if you like, to the second db directly with ADOdb. Example:

$acon = NewADOConnection('oci8');
$acon->NLS_DATE_FORMAT = 'RRRR-MM-DD HH24:MI:SS';
$acon->charSet = 'AL32UTF8';
$acon->Execute("ALTER SESSION SET NLS_DATE_FORMAT='RRRR-MM-DD HH24:MI:SS'");
$acon->PConnect('host', 'user', 'pass');
$acon->Execute("oracle sql");

Message copied from Datahell : https://forum.elxis.org/index.php?topic=3025.msg18759#msg18759
Title: Re: Connect on second database
Post by: gsot on February 08, 2011, 14:22:40
I took a look on this post https://forum.elxis.org/index.php?topic=3025.0 (https://forum.elxis.org/index.php?topic=3025.0).

Thank you for your answer, I have already checked this post.
For me, the way I mentioned above has worked fine, I am just curious if the same thing can be done through the elxis $database object.
Title: Re: Connect on second database
Post by: webgift on February 08, 2011, 14:38:14
As datahell has mentioned and i think it's clear. This can't be done through $database object.