[Templates] Using DBI plugin to access a remote database
Richard Clamp
richardc@unixbeard.net
Tue, 12 Sep 2006 16:02:49 +0100
Jeremiah Foster wrote:
> On Tue, 2006-09-12 at 14:41 +0100, Dave Howorth wrote:
>> Jeremiah Foster wrote:
>>> Is there a syntax for adding a remote host in the foo.tt file to access
>>> a database that I should know? Or do I have to do everything from the
>>> local host?
>> There's nothing special I know of. Just give the DSN to USE DBI:
>>
>> USE DBI( my_dsn );
>>
>
> I am doing something similar;
>
> [% USE DBI %] [% DBI.connect('dbi:mysql:my_website', 'db_user',
> 'double_extra_secret') %]
>
> Then I am doing
>
> [% FOREACH item = DBI.query('SELECT * from table') %]
>
>
> But if I change the DBI.connect line to include my remote host thusly;
>
> [% USE DBI %] [% DBI.connect('dbi:mysql:my_website', 'db_user',
> 'double_extra_secret', 'remote_host') %]
>
> it fails to work. This is why I suspect a syntax error despite the lack
> of warnings in the logs, perl -C saying no syntax issues and no mention
> of a remote host in perldoc DBI::Template::Plugins.
>
> I must be doing something wrong. Just not sure where.
You're not specifying your DSN correctly.
'dbi:mysql:my_website'
needs to become
'dbi:mysql:my_website;host=remote_host'
There's no magic 4th argument.
--
Richard Clamp <richardc@unixbeard.net>