This * should * work and should not cause a core dump.

That said, you should take a look at the O'Rielly DBI book. There are a
ton of error conditions that you're not checking here.

Best to turn on RaiseError and then wrap all subsequent code in an eval
block. Your code will be cleaner and easier to read, and you'll catch all
possible errors.

On Tue, 12 Sep 2000 [EMAIL PROTECTED] wrote:

> Hi all,
> 
> I got the following weird problem about DBI in mod_perl.
> 
> Just a simple script which can run in the "cgi-bin",but failed in the mod_perl.
> When I check the error_log, I find the message:
> [Tue Sep 12 12:01:59 2000] [notice] child pid 1273 exit signal Segmentation fault 
>(11)
> 
> My linux box:
>       perl 5.005_03, 
>       Apache/1.3.12 (Unix) with mod_perl/1.24,
>       DBI-1.14,
>       Mysql 3.22.32
> 
> The http.conf about mod_perl:
>     Alias /perl/ "/usr/local/apache/cgi-bin/"
>     PerlTaintCheck On
>     <Location /perl>
>         AllowOverride None
>         setenv MOD_PERL_TRACE ALL
>         PerlSetupEnv Off
>         SetHandler perl-script
>         PerlHandler Apache::Registry
>         PerlModule DBI CGI DBD::mysql
>         PerlSetEnv PERL_DESTRUCT_LEVEL -1
>         Options +ExecCGI
>         Order allow,deny
>         Allow from all
>     </Location>
> 
> The troublesome script is here:
> >>>------------------------------------------------------
> #!/usr/bin/perl -w
> 
> use CGI qw/:standard/;
> use CGI::Carp 'fatalsToBrowser';
> use DBI;
> use strict;
> 
> my $query= new CGI;
> my $dsn="DBI:mysql:database=authuser;host=localhost;port=3306";
> my $loginname="test";
> my $password="test";
> my @table;
> my ($dbh,$sth,$fields,$nums,$cols);
> 
> print $query->header();
> print $query->start_html(-title=>'hello');
> print h3({-align=>'center'},"database");
> print "<center>";
> 
> print "<table border=1>";
> print "<tr>";
> 
> $dbh=DBI->connect($dsn,$loginname,$password,{RaiseError=>1}) || die "Can't 
>connect!\n";
> $sth=$dbh->prepare("describe MemberAuth");
> $sth->execute();
> # list the column of the table
> $fields=$sth->fetchall_arrayref();
>         foreach $nums (@$fields) {
>                 foreach $cols (@$nums[0]) {
>                 print "<td width=150 align=center>",$cols,"</td>";
>         }
> }
> print "</tr>";
> 
> $sth=$dbh->prepare("select * from MemberAuth");
> $sth->execute();
> # show the records of the table
> while(@table=$sth->fetchrow_array()) {
>         print "<tr>";
>         foreach my $data (@table) {
>                print "<td width=150 align=center>",$data,"</td>";
>         }
>         print "</tr>";
> }
> $sth->finish();
> $dbh->disconnect;
> 
> print "</center>";
> print $query->end_html;
> 
> >>>---------------------------------------------------------------
> 
> Any help will be appreciated!
> 

-- 
-- Tom Mornini
-- InfoMania Printing and Prepress

Reply via email to