1

I am sorry if this may be a silly question for you all,but I don't know what to do. I am trying to connect to a local database using perl. When I try to run the command I get below error

DBD::mysql::st execute failed: Table 'RegenMedline.user_tables' doesn't exist at Medlineparser.pl line 639.

My line 639 is something like this:

$main::dbh = DBI->connect("dbi:mysql:databasename", 
                       $main::user="username", 
                       $main::password="password",
                       {PrintError => 1,
                        RaiseError => 1,
                        AutoCommit => 1})
                        or die "Can't connect to database: $DBI:errstr\n"; 

my $sth = $main::dbh->prepare("
                SELECT table_name
                FROM user_tables");

$sth->execute();

while (my ($table_name) = $sth->fetchrow_array()){
  print "table_name = $table_name\n";
}

I hope this snippet helps and I have put my question in right way. Let me now if I need to give more information. Any help is greatly appreciated.

3
  • It's kind of strange that MySQL doesn't find RegenMedline.user_tables, while you have done something like SELECT table_name FROM RegenMedline.samples. Commented Sep 19, 2011 at 14:24
  • I am really sorry for that. I have edited the code. I was playing with the code and I forgot to edit it back to user_tables. Thank you for pointing that out. Commented Sep 19, 2011 at 14:31
  • 1
    This isn't your problem, but $table_name is a list reference, not a scalar. You'll want to say something like print "table_name = $table_name->[0]\n" Commented Sep 19, 2011 at 15:01

1 Answer 1

2

Does it work from command line?

> mysql -u username -ppassword 

mysql> select * from RegenMedline.user_tables
Sign up to request clarification or add additional context in comments.

4 Comments

Well, to be true my database is empty and the command gives me zero results. So, I think it works. I am using this code to parse XML files and populate the database, both working simultaneously. There are no user_tables in my database. I have created the tables and I have used them later in the code. To be true, I got this code from another site which is a open source. I hope I answered your question.
@sma I sense a similarity between your statement "There are no user_tables in my database" and the error "Table 'RegenMedline.user_tables' doesn't exist".
If I get it right, you are building the database in your program: when you start the program you have an empty database with no tables ( right? ). You have statements like CREATE TABLE user_tables in your program?
Well, I have already created the tables and user_tables take those values later in the code. I just deleted that thing and it works fine for me now. Thank you all for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.