56 users online (0 members and 56 guests)  


  Results 1 to 3 of 3

Related

  1. FTP won't connect...    Forum: Databases
    Replies: 5
  2. How to connect to database mysql    Forum: Databases
    Replies: 1
  3. remote connect to Mysql    Forum: PHP Forum
    Replies: 8
  4. i can connect, but i can't do anything    Forum: Databases
    Replies: 2
  5. Unable to download file    Forum: CGI Perl Forum
    Replies: 3
  1. #1
    saishkumar's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2006
    Posts
    1

    Unable to connect to database

    Hi all

    I am using active Perl 5.8.8 and apache 2.0.55 in window xp professional
    I am using MySql as my database
    I want to run a sample database application in PERL.
    I installed DBI and DBD-MySql in perl
    I used the following sample code

    **************************************************************
    #!E:\Program Files\bin\perl.exe

    Use DBI;

    print <<END;
    Content-type: text/html

    <html>
    <head>
    <title>Example of Perl calling MySQL</title>
    </head>

    <body bgcolor="white">

    END

    # database information
    my $db="samp";
    my $host="mysql:localhost";
    my $userid="nanna";
    my $passwd="secret";
    my $connectionInfo='dbi:mysql:$db:localhost:3306';
    # make connection to database


    my $dbh = DBI->connect($connectionInfo, $userid, $passwd);


    *************************************************************



    but I am not able to connecting to MySQL database

    any type of help is approciatable
    thanks and regards
    saish

  2. #2
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Unable to connect to database

    Try changing the connection info string:
    Code:
    my $connectionInfo = 'dbi:mysql:database=$db;host=localhost:3306'
    I don't use PERL, but from a bit of searching it looks like you're missing the "database=" and "host=" parts of the connection command.
    Oh yes - and it looks like it should be a semicolon between db & host, not a colon.

  3. #3
    uthus's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2006
    Location
    Ft Hood
    Posts
    75

    Re: Unable to connect to database

    The following always works for me.
    from Sams Teach Yourself MySQL in 21 Days:

    use DBI;
    $database = "database";
    $driver = "mysql";
    $user = "whomever";
    $password = "secret";
    $SQL = "insert into ...";

    $dsn = "DBI:$driver:database=$database" or die(connectError());
    my $dbh = DBI->connect($dsn, $user, $password) or die(connectError());
    my $sth = $dbh->prepare($SQL);

    $sth->execute();


    hth,

    u



Tags for this Thread