Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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

by peppiv (Curate)
on Jan 22, 2002 at 01:18 UTC ( #140496=note: print w/replies, xml ) Need Help??

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

Yes! You were right. It was in my original statement. In fact, it says no database selected. (Which is obvious now why it didn't return any results). Even though I included the exact and full path.

Is there a better way to select the database if it's in a different directory other than f_dir= ?
  • Comment on Re: Re: DBI::mysql fetch() without execute() PROBLEM

Replies are listed 'Best First'.
Re: Re: Re: DBI::mysql fetch() without execute() PROBLEM
by cfreak (Chaplain) on Jan 22, 2002 at 01:29 UTC

    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


      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/ 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?).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://140496]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (1)
As of 2018-07-23 02:18 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (459 votes). Check out past polls.