[support] Dynamic remote database access

Ms. Nancy Wichmann nan_wich at bellsouth.net
Mon Jul 11 22:02:14 UTC 2011


This is what I wrote to him:I haven't even gotten as far as to use db_set_active. I was just checking that the settings.php worked as intended, which it does not. Try it on your local site: enter another db connection, but with an incorrect password. At the very least, authentication is happening whether you are physically accessing the DB or not. And when I tried accessing a truly remote DB with correct userid and password, it failed because MySql was trying to add my local IP address to the userid. In this case, I am not an admin in any way, shape, or form on the remote DB and cannot even try adding a user id containing the IP address (whatever it may be today).
 
If this were not under Drupal, I would just try a straight mysql_connect, but i don't think that is very Drupally.
 
I had thought about doing as you suggest; it feels a bit hokey, but would work except that it could take the site down at that moment. You've undoubtedly seen what happens when you have your database password wrong. That same things happens if the remote database is unavailable. I don't want that happenning. But maybe I can do the mysql_connect to check first, then do what you suggest. 
Nancy
 
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.

From: Michael Prasuhn <mike at mikeyp.net>
>To: support at drupal.org
>Sent: Monday, July 11, 2011 3:28 PM
>Subject: Re: [support] Dynamic remote database access
>
>1) I don't see a reply to Mr. Metzler.
>
>2) What we've said to you is 100% accurate. Unless you try to query the 
>site (which you're already said you only do on cron), Drupal will ignore 
>the extra db connection string, and your site will be fine. $db_url is 
>just a global variable that holds configuration.
>
>3) If it's really such a big deal then do something like this:
>
><?php
>
>// Oh I need to connect to another DB
>global $db_url;
>$cur_db = $db_url;
>$db_url = array('default' => $cur_db, 'another_db' => 
>'mysqli://user:pass@host/dbname');
>db_set_active('another_db');
>$result = db_query('SELECT * FROM table');
>db_set_active();
>
>//....process $result
>
>-Mike
>
>
>Ms. Nancy Wichmann wrote:
>> Not true -- see my reply to Mr. Metzler.
>> /*Nancy*/
>> Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L.
>> King, Jr.
>>
>>    *From:* Michael Prasuhn <mike at mikeyp.net>
>>    *To:* support at drupal.org; Ms. Nancy Wichmann <nan_wich at bellsouth.net>
>>    *Sent:* Monday, July 11, 2011 3:02 PM
>>    *Subject:* Re: [support] Dynamic remote database access
>>
>>    Drupal 6 is pretty much going to ignore any additional (non-default)
>>    connections specified, if $db_url is an array(), unless you try to
>>    connect. No problem putting the connection string there and using
>>    only when you need it. This is even true for DBTNG backport module,
>>    although it has other ways of setting up connections after Drupal
>>    has boostrapped.
>>
>>    -Mike
>>
>>
>>    Ms. Nancy Wichmann wrote:
>>      > No, the $db_url method simply will not work because we cannot
>>    guarantee
>>      > that the remote will always be accessible. If it's not, there is no
>>      > reason why our site should not be. Once in a while (cron), we
>>    need to go
>>      > get some data from that database; if it's not available at that
>>    time, we
>>      > will merely log the error and try later.
>>      > /*Nancy*/
>>      > Injustice anywhere is a threat to justice everywhere. -- Dr.
>>    Martin L.
>>      > King, Jr.
>>      >
>>      > *From:* Fred Jones
>>      >
>>      > Not clear what the question is. does this help:
>>      > http://drupal.org/node/18429
>>      >
>>      > On Mon, Jul 11, 2011 at 9:35 PM, Ms. Nancy Wichmann wrote:
>>      > > I know that the "standard" way to access another database is to
>>      > include it
>>      > > in $db_url in the settigs.php file. This has the undesireable
>>      > effect that
>>      > > the remote database must be available all the time. In my case,
>>      > we only need
>>      > > to access the remote DB a few times a week via a cron job, where
>>      > much better
>>      > > error handling is available. I haven't yet found a way (I'm still
>>      > searching
>>      > > DO) to do this. Does anyone have any good ideas? This is Drupal 6
>>      > - don't
>>      > > bother suggesting an upgrade. Replication is probably not an
>>      > option because
>>      > > we shouldn't have access to, nor need, everything in the remote DB.
>>      >
>>
>>    -- __________________
>>    Michael Prasuhn
>>    503.512.0822 office
>>    mike at mikeyp.net <mailto:mike at mikeyp.net>
>>    http://mikeyp.net
>>
>>
>
>-- 
>__________________
>Michael Prasuhn
>503.512.0822 office
>mike at mikeyp.net
>http://mikeyp.net
>-- 
>[ Drupal support list | http://lists.drupal.org/ ]
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110711/6d7c4797/attachment-0001.html 


More information about the support mailing list