Creating a DSN-less connection to a MySQL database

Discussion in 'Perl Misc' started by Al Reynolds, Sep 9, 2003.

  1. Al Reynolds

    Al Reynolds Guest

    Hello,

    I hope someone will be able to help me with this.

    I am trying to set up a connection to my MySQL
    database using perl. I already have the database
    set up and have used it with PHP without any problems.

    When I try and execute the following code, I get an error:
    (obviously I have substituted the names/passwords)

    #!/usr/bin/perl
    use DBI;
    my $dbh =
    DBI->connect('DBI:mysql:databasename:localhost','username','password');
    $dbh->disconnect or warn "Disconnection error: $DBI::errstr\n";
    exit;

    I contacted the service provider and they replied:
    "Using this code, are you trying to create a dsn-less
    (adodb) connection, as opposed to dsn (odbc), because
    only the former is supported on our hosting packages?"

    I think I understand from what I have read so far that I
    am currently trying to create a dsn connection, but I might
    well be completely wrong about that! Does what the ISP
    said make sense?

    Can I use DBI to create a dsn-less (ADODB) connection,
    or do I need to use something completely different?

    IN ASP, I would need to use CreateObject('ADODB.Connection')
    Is there something similar I can use in Perl?

    The perl version is 5.00503
    DB_File, CGI, DBI and DBD-Mysql modules are installed.

    Server software is:
    Apache/1.3.20 Sun Cobalt (Unix) Chili!Soft-ASP/3.6.2
    mod_ssl/2.8.4 OpenSSL/0.9.6b PHP/4.1.2
    mod_auth_pam_external/0.1 FrontPage/4.0.4.3 mod_perl/1.25

    Thanks in advance,
    Al Reynolds
    Al Reynolds, Sep 9, 2003
    #1
    1. Advertising

  2. On Tue, 9 Sep 2003 13:37:09 +0100
    "Al Reynolds" <> wrote:
    > I hope someone will be able to help me with this.
    >
    > I am trying to set up a connection to my MySQL
    > database using perl. I already have the database
    > set up and have used it with PHP without any problems.
    >
    > When I try and execute the following code, I get an error:
    > (obviously I have substituted the names/passwords)
    >
    > #!/usr/bin/perl
    > use DBI;
    > my $dbh =
    > DBI->connect('DBI:mysql:databasename:localhost','username','passwor
    > d');$dbh->disconnect or warn "Disconnection error: $DBI::errstr\n";
    > exit;


    Try to first, read the documentation for DBD::mysql and second, try to
    connect using ...

    DBI->connect('DBI:mysql:database=dbname;host=localhost',
    'username',
    'password')
    or die "Connection error: ".$DBI::errstr."\n";

    If you had read the documentation, you would have discovered that your
    connection statement is wrong.

    HTH

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. http://www.gnu.org/licenses/gpl.txt
    for more information.

    a fortune quote ...
    Never offend people with style when you can offend them with
    substance. -- Sam Brown, "The Washington Post", January 26,
    1977
    James Willmore, Sep 9, 2003
    #2
    1. Advertising

  3. Al Reynolds

    Al Reynolds Guest

    "James Willmore" <> wrote in message
    news:...
    > On Tue, 9 Sep 2003 13:37:09 +0100
    > "Al Reynolds" <> wrote:
    > > I hope someone will be able to help me with this.
    > >
    > > I am trying to set up a connection to my MySQL
    > > database using perl. I already have the database
    > > set up and have used it with PHP without any problems.
    > >
    > > When I try and execute the following code, I get an error:
    > > (obviously I have substituted the names/passwords)
    > >
    > > #!/usr/bin/perl
    > > use DBI;
    > > my $dbh =
    > > DBI->connect('DBI:mysql:databasename:localhost','username','passwor
    > > d');$dbh->disconnect or warn "Disconnection error: $DBI::errstr\n";
    > > exit;

    >
    > Try to first, read the documentation for DBD::mysql and second, try to
    > connect using ...
    >
    > DBI->connect('DBI:mysql:database=dbname;host=localhost',
    > 'username',
    > 'password')
    > or die "Connection error: ".$DBI::errstr."\n";
    >
    > If you had read the documentation, you would have discovered that your
    > connection statement is wrong.


    I read enough to decide that the using DBI would
    generate a DSN connection*, which wasn't what I
    wanted, which is why I gave up on the DBI route
    to pursue the ADODB route. The code I used is
    referred to in several perl-related resources and
    tutorials on different web sites; I doubt that they
    all made the same mistake. It isn't that uncommon
    for a call to be possible in a variety of forms.

    Anyway, thank you for the code snippet. If I am
    trying to make a DBI connection again I will use it.

    FWIW, I solved the problem using the older
    mysql.pm module, which is less portable when
    there is a possibility that the database type could
    change later. It works fine just now though.

    Cheers,
    Al


    * This may be wrong of course - I am still not quite clear
    on the matter. There is surprisingly little info online about
    the difference between DSN and DSN-less database
    connections and how to set them up using perl.
    Al Reynolds, Sep 10, 2003
    #3
  4. "Al Reynolds" <> wrote in message news:<bjn7n4$et28p$>...
    > "James Willmore" <> wrote in message
    > news:...
    > > On Tue, 9 Sep 2003 13:37:09 +0100
    > > "Al Reynolds" <> wrote:
    > > > I hope someone will be able to help me with this.
    > > >
    > > > I am trying to set up a connection to my MySQL
    > > > database using perl. I already have the database
    > > > set up and have used it with PHP without any problems.
    > > >
    > > > When I try and execute the following code, I get an error:
    > > > (obviously I have substituted the names/passwords)
    > > >
    > > > #!/usr/bin/perl
    > > > use DBI;
    > > > my $dbh =
    > > > DBI->connect('DBI:mysql:databasename:localhost','username','passwor
    > > > d');$dbh->disconnect or warn "Disconnection error: $DBI::errstr\n";
    > > > exit;

    > >
    > > Try to first, read the documentation for DBD::mysql and second, try to
    > > connect using ...
    > >
    > > DBI->connect('DBI:mysql:database=dbname;host=localhost',
    > > 'username',
    > > 'password')
    > > or die "Connection error: ".$DBI::errstr."\n";
    > >
    > > If you had read the documentation, you would have discovered that your
    > > connection statement is wrong.

    >
    > I read enough to decide that the using DBI would
    > generate a DSN connection*, which wasn't what I
    > wanted, which is why I gave up on the DBI route
    > to pursue the ADODB route. The code I used is
    > referred to in several perl-related resources and
    > tutorials on different web sites; I doubt that they
    > all made the same mistake. It isn't that uncommon
    > for a call to be possible in a variety of forms.
    >
    > Anyway, thank you for the code snippet. If I am
    > trying to make a DBI connection again I will use it.
    >
    > FWIW, I solved the problem using the older
    > mysql.pm module, which is less portable when
    > there is a possibility that the database type could
    > change later. It works fine just now though.
    >
    > Cheers,
    > Al
    >
    >
    > * This may be wrong of course - I am still not quite clear
    > on the matter. There is surprisingly little info online about
    > the difference between DSN and DSN-less database
    > connections and how to set them up using perl.


    I had to review the ADODB manual to find out what you meant by
    "DSN-less" database. In general, anything ADODB, DBI can do. There
    is the DBD::ODBC module that you can use to connect to data sources
    such as Access. You can also use DBD::proxy to create a client/server
    type connection.

    Basically - this is a term that ADODB authors came up with. You still
    need to declare a data source using a "DSN-less" connection. So, the
    term is mis-leading.

    HTH

    Jim
    James Willmore, Sep 10, 2003
    #4
  5. Al Reynolds

    Al Reynolds Guest

    "James Willmore" <> wrote in message
    news:...
    > "Al Reynolds" <> wrote in message

    news:<bjn7n4$et28p$>...
    > > "James Willmore" <> wrote in message
    > > news:...
    > > > On Tue, 9 Sep 2003 13:37:09 +0100
    > > > "Al Reynolds" <> wrote:
    > > > > I hope someone will be able to help me with this.
    > > > >
    > > > > I am trying to set up a connection to my MySQL
    > > > > database using perl. I already have the database
    > > > > set up and have used it with PHP without any problems.
    > > > >
    > > > > When I try and execute the following code, I get an error:
    > > > > (obviously I have substituted the names/passwords)
    > > > >
    > > > > #!/usr/bin/perl
    > > > > use DBI;
    > > > > my $dbh =
    > > > > DBI->connect('DBI:mysql:databasename:localhost','username','passwor
    > > > > d');$dbh->disconnect or warn "Disconnection error: $DBI::errstr\n";
    > > > > exit;
    > > >
    > > > Try to first, read the documentation for DBD::mysql and second, try to
    > > > connect using ...
    > > >
    > > > DBI->connect('DBI:mysql:database=dbname;host=localhost',
    > > > 'username',
    > > > 'password')
    > > > or die "Connection error: ".$DBI::errstr."\n";
    > > >
    > > > If you had read the documentation, you would have discovered that your
    > > > connection statement is wrong.

    > >
    > > I read enough to decide that the using DBI would
    > > generate a DSN connection*, which wasn't what I
    > > wanted, which is why I gave up on the DBI route
    > > to pursue the ADODB route. The code I used is
    > > referred to in several perl-related resources and
    > > tutorials on different web sites; I doubt that they
    > > all made the same mistake. It isn't that uncommon
    > > for a call to be possible in a variety of forms.
    > >
    > > Anyway, thank you for the code snippet. If I am
    > > trying to make a DBI connection again I will use it.
    > >
    > > FWIW, I solved the problem using the older
    > > mysql.pm module, which is less portable when
    > > there is a possibility that the database type could
    > > change later. It works fine just now though.
    > >
    > > Cheers,
    > > Al
    > >
    > >
    > > * This may be wrong of course - I am still not quite clear
    > > on the matter. There is surprisingly little info online about
    > > the difference between DSN and DSN-less database
    > > connections and how to set them up using perl.

    >
    > I had to review the ADODB manual to find out what you meant by
    > "DSN-less" database. In general, anything ADODB, DBI can do. There
    > is the DBD::ODBC module that you can use to connect to data sources
    > such as Access. You can also use DBD::proxy to create a client/server
    > type connection.
    >
    > Basically - this is a term that ADODB authors came up with. You still
    > need to declare a data source using a "DSN-less" connection. So, the
    > term is mis-leading.
    >
    > HTH


    Cheers - it does.
    Al
    Al Reynolds, Sep 11, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Appelmans

    oleDbConnection with DSN less connection string?

    Michael Appelmans, Jun 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    189
    Michael Appelmans
    Jun 4, 2004
  2. Gameface

    ASP Dsn-less connection error

    Gameface, May 3, 2004, in forum: ASP General
    Replies:
    2
    Views:
    92
    Ray at
    May 3, 2004
  3. shank

    SQL and DSN-Less connection

    shank, Jul 21, 2004, in forum: ASP General
    Replies:
    1
    Views:
    95
    Aaron [SQL Server MVP]
    Jul 21, 2004
  4. A P
    Replies:
    1
    Views:
    165
    Joker
    Sep 29, 2004
  5. Rob Meade
    Replies:
    7
    Views:
    144
    Lance Wynn
    Jan 2, 2005
Loading...

Share This Page