PaganJim has asked for the wisdom of the Perl Monks concerning the following question:
Hello everyone. I have been away from PERL for quite a while, a few years actually. But I was looking at an old script that I wrote that I want to resurrect from the dead, so to speak. The old script was basically to help me learn now I am using that way again but it will go back up on the web at some point. When I originally wrote it, I didn't need a database, I just had a small amount of data that I kept in txt files. But now, I am expecting a lot more data so I am trying to move it to a db. I have a db and table populated with info. So I am trying to write a script to read the db line by line using fetchrow_array. But for some reason the script keeps popping a 500 error and there is nothing in my log files.
So the script so far seems pretty straight forward but I cannot for the life of me find the error. And no errors show up in my error logs and no error is displayed. Anyone see anything? All feedback greatly appreciated since I am just getting back into perl.
#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use DBI; ## mysql user database name $db ="dbname"; ## mysql database user name $user = "dbuser"; ## mysql database password $pass = "abc123"; ## user hostname $host="localhost"; my $dsn = "DBI:mysql:database=$db;host=$host"; my $dbh = DBI->connect($dsn, $user, $pass) or die("Error connecting to the database: $DBI::errstr\n"); my $sql = qq/select * from table/; my $sth = $dbh->prepare ($sql); while (@row = $sth->fetchrow_array) { my ($a, $b, $c, $d ) = @row; print ("--", @row), "\n\n"; } $dbh->disconnect (); exit (0);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: read database 500 error
by haukex (Archbishop) on Aug 08, 2021 at 20:14 UTC | |
by Anonymous Monk on Aug 09, 2021 at 09:37 UTC | |
|
Re: read database 500 error
by Bod (Parson) on Aug 08, 2021 at 21:31 UTC | |
|
Re: read database 500 error
by dsheroh (Monsignor) on Aug 09, 2021 at 07:25 UTC | |
by PaganJim (Initiate) on Aug 10, 2021 at 20:24 UTC |