Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Re: DBI::mysql fetch() without execute() PROBLEM

by cfreak (Chaplain)
on Jan 22, 2002 at 01:29 UTC ( [id://140500]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: DBI::mysql fetch() without execute() PROBLEM
in thread DBI::mysql fetch() without execute() PROBLEM

I should have seen that right away. You are trying to connect to a mysql database with syntax for the DBI::CSV module. When using the mysql driver connect like this:

my $dsn = "DBI:mysql:database=your_db_name;host=your_hostname;"; my $dbh = DBI->connect($dsn,'your_db_username','your_db_password') or +die "Couldn't connect to database";

So instead of "f_dir" use "database=" and make sure to put the host name. If you are trying to use a comma separated file somewhere on your system then you should use the CSV driver, just keep using the f_dir part and put "CSV" where you have "mysql".

Hope that helps

Chris

Replies are listed 'Best First'.
Re: Re: Re: Re: DBI::mysql fetch() without execute() PROBLEM
by peppiv (Curate) on Jan 22, 2002 at 20:47 UTC
    Thanks for the catch. I actually had it that way once, but since I couldn't get it to work I dropped it.

    #!/usr/bin/perl -w use strict; use DBI; use CGI::Carp qw(fatalsToBrowser); use CGI qw (:standard); print "Content-type: text/html\n\n"; my $dbh = DBI->connect(qq{DBI:mysql:database=subscriptions;host=l +ocalhost,I DON'T HAVE A USERNAME AND PASSWORD OTHER THAN ROOT}, {Rais +eError => 1} ); my $sth = $dbh->prepare( q{SELECT email FROM contacts WHERE state + = ?} ); $sth->execute('OH') or die $sth->errstr; while (my @result = $sth->fetchrow_array()) { print "@result\n"; } # check for problems which may have terminated the fetch early die $sth->errstr if $sth->err; $dbh->disconnect;

    I've tried many things to connect but to no avail. \s tells me that I'm connected via a UNIX socket. I can only find docs about different ports. Could this be a problem?

    Can't call method "prepare" on an undefined value at /usr/local/etc/ht +tpd/cgi-bin/DBI_mysql_01.pl line 12.

    Is there any way to view the path or connection?
      even if you don't have a password you should still put in the username. I'm not sure what you mean by \s. You should also make sure your mysql database is running. (i.e. Can you connect to it using the mysql client?).
        Things I've learned.

        \s is the command you type in when you're in the mysql client. It tells you lots of cool information. Who you're logged in as, your connection, etc. Very neat.

        Also, I've learned to run "top" in Telnet. It tells me all the processes running. Including the mysqld.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://140500]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found