Can't call method "execute" on an undefined value at

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ticfranca
    New Member
    • May 2007
    • 14

    #16
    Originally posted by KevinADC
    Make the change I suggested above (change the semi-coln ';' to a colon ':') and try your script again.

    But also change this:

    $sth.execute;

    back to:

    $sth->execute() or die $dbh->errstr;

    $sth.execute is not going to do anything.
    I replaced semi-colons and then the connection failed.
    I return to $sth->execute() or die $dbh->errstr;, then i get internal server error again.

    I'm desperated....I try ...try ...try and the script doesn't works.

    Thanks Kevin

    Comment

    • ticfranca
      New Member
      • May 2007
      • 14

      #17
      Error "Intern al Server Error" on the execute command line

      Merged Thread. Title: Error "Internal Server Error" on the execute command line

      I have a script and in the line

      $sth->execute or die $dbh->errstr;

      i get an error INTERNAL SERVER ERROR

      I saw many tutorials and already checked the permissions in 755, Perl path , possibles wrong @ and $ on the script and everything is right.


      below my complete sub



      sub Pega_recorde {
      my $database = 'bundinha';
      my $host = 'localhost';
      my $usuario = 'morad';
      my $senha = 'm8x2';

      my $dbh = DBI->connect("DBI:m ysql:database=$ database:host=$ host",$usuario, $senha) or die "Can't open DB: $!";

      my $sth = $dbh->prepare(q{SELE CT pontos FROM bundinha_rank}) ;
      $sth->execute or die $dbh->errstr;
      while (@record = $sth->fetchrow_array ()) {
      $pontos = $record[6];
      }
      $sth->finish;
      $dbh->disconnect;
      }

      When I take off the line in bold from script, it works fine. What's wrong in my execute() command?


      Somebody help me

      Thiago

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #18
        Look in the server error log if possible. At this point I do not know why you are getting an internal server error.

        Comment

        • ticfranca
          New Member
          • May 2007
          • 14

          #19
          Merged Thread Title: Error perl recolocation

          I tried to execute my cgi file in linux by command line for check error because by browser i had the message internal server error.

          I get an error like that:

          perl: relocation error: /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/DBD/mysql
          /mysql.so: undefined symbol: mysql_warning_c ount

          What would be this error...can somebody help me?

          thanks.

          Thiago

          Comment

          • ticfranca
            New Member
            • May 2007
            • 14

            #20
            I executed it by linux command line and it returns me an error like that:


            perl: relocation error: /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/DBD/mysql/mysql.so: undefined symbol: mysql_warning_c ount

            Did you know something about this error?

            Comment

            • KevinADC
              Recognized Expert Specialist
              • Jan 2007
              • 4092

              #21
              Are you running mod_perl? If so see if anything here is helpful:

              mod_perl_traps( 3) - Linux man page

              Comment

              • ticfranca
                New Member
                • May 2007
                • 14

                #22
                Somebody help me! please

                Comment

                • miller
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1086

                  #23
                  Hello ticfranca,

                  It sounds very much like you are new to both DBI and MySQL and maybe even perl. I would suggest that you start a little smaller when trying to get this setup properly at the admin level before moving on to cgi and apache integration.

                  Take this little script for example. You simply run it from the command prompt and it connects to MySQL and prints out the tables in the database that you specify. If you can't get this to work, then hopefully you can track down the problem to either something with the configuration of your mysql server, or maybe your connect string information.

                  [CODE=perl]
                  #! /usr/bin/perl

                  use DBI;

                  use strict;

                  # Database Connect Values
                  my $name = 'bundinha';
                  my $user = 'myhumoradm';
                  my $pass = 'my8xr2d2';
                  my $host = 'localhost';

                  # Database URL
                  my $url = "dbi:mysql:$nam e:$host";

                  my $dbh = DBI->connect($url , $user, $pass) or die "Database connection failed.";

                  # Determine Existing Tables
                  my $name;
                  my $sth = $dbh->prepare(q{SH OW TABLES});
                  $sth->execute or die $dbh->errstr;
                  $sth->bind_columns(\ $name);
                  while ($sth->fetch) {
                  print "$name\n";
                  }
                  $sth->finish; undef $sth;

                  $dbh->disconnect; undef $dbh;

                  1;

                  __END__
                  [/CODE]

                  When I run this on my local machine, I get the following results:

                  Code:
                  > perl scratch.pl
                  DBI connect('bundinha:localhost','myhumoradm',...) failed: Can't connect to MySQL server on 'localhost' (10061) at scratch.pl line 16
                  Database connection failed. at scratch.pl line 16.
                  This is good, because I don't actually have mysql installed on my home computer so it's no surprise that it can't connect to MySQL server.

                  On my development machine I get the following results
                  Code:
                  $ perl scratch.pl 
                  DBI->connect(bundinha:localhost) failed: Access denied for user: 'myhumoradm@localhost' (Using password: YES) at scratch.pl line 16
                  Database connection failed. at scratch.pl line 16.
                  This is also as expected because while I have a MySQL server, I have no permissions setup for user myhumoradm.

                  Getting DBI to work is all about putting yourself in a position to receive meaningful error messages. Without those you can never come close to knowing how to fix something that goes wrong.

                  Your first error message was meaningful, although you didn't know what it meant. Can't call method "execute" on an undefined value at This meant quite simply that the object that you were trying to run execute on was undefined. This led me to immediately ask, what value or object is this error message talking about? Well, it could only be one, $sth. Then I ask why is this value undefined? Well, the only way to know this is to look at the previous line and see that your assignment was malformed because of the inclusion of the if statement. You fixed that, great.

                  Next you came back with an "Internal Server Error". Well this means that your apache server died for some reason, but unfortunately you don't know the reason. Well, we can presume that because you only changed two lines that the die was in this line "$sth->execute() or die $dbh->errstr". However, to be able to diagnose this we must know what the errstr was. To get this you either need to look at the error log or run the cgi script outside of the apache environment, which you eventually decided to do.

                  This lead you to the next clue. " perl: relocation error: ... undefined symbol: mysql_warning_c ount". Guess what, I have no idea what this means, so the quickest place to be enlightened is google. This actually doesn't bring up too much information other than what this function is. "Descriptio n: Returns the number of warnings generated during execution of the previous SQL statement. ". This isn't very enlightening although it does tell us that DBI is at least trying to work.

                  So this brings me to my only suggested approach. Limit the number of possible causes by reducing your MySQL code to the minimum necessary to test if things are working. The script that I just provided should do that, and if this works, then see about testing the exact query that you use in your cgi script.

                  Then if that works see about importing it into a basic CGI script. And on and on, slowly adding layers of uncertainty and risk until you either reach your final goal or something breaks that you can recognize and diagnose.

                  This is called debugging. It's tedious. But it's something that all programmers and developers have to learn as we all make mistakes. We just must aim to setup our environments to minimize risk and be certain that errors are reported in meaningful ways.

                  Good luck,
                  - Miller

                  Comment

                  • KevinADC
                    Recognized Expert Specialist
                    • Jan 2007
                    • 4092

                    #24
                    Originally posted by ticfranca
                    Somebody help me! please
                    Did you bother to read the page I linked you to?

                    Comment

                    Working...