how to fix error attempt to prepare on inactive database handle in SQLite

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wiinie
    New Member
    • Feb 2011
    • 47

    how to fix error attempt to prepare on inactive database handle in SQLite

    Code:
    sub languages{
    	my $self = shift;
    	
    	if (!$self->{LANGUAGE})
    	{
    		my @language = ();
    		my $statement = $db1->prepare("select Id, Name, syllableData from language");
    		$statement->execute();
    
    		while(my @array = $statement->fetchrow_array()){
    			my ($id , $name, $syllableData) = @array;
    			push (@language, $object);				
    		}	
    		$statement->finish();
    		$db1->disconnect  or warn $db1->errstr;
    		$self->{LANGUAGE} = \@language;
    	}
    	return $self->{LANGUAGE};
    }
    I have a problem to disconnect the db1 ,, can someone help me?
    and I got this error "DBD::SQLite::d b prepare failed: attempt to prepare on inactive database handle at C: ~~~~"
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    Why are you disconnecting from the db? That's making your subsequent calls to prepare fail.

    Just remove this line:

    Code:
    $db1->disconnect  or warn $db1->errstr;

    Comment

    • Wiinie
      New Member
      • Feb 2011
      • 47

      #3
      but i have to disconnect the db. so how can i do if i want to do it
      because my db locate outside of the sub..

      Comment

      • miller
        Recognized Expert Top Contributor
        • Oct 2006
        • 1086

        #4
        If you're going to disconnect from the db, then you need to reconnect next time you want to do a sql statement.

        That's what the error is telling you: "DBD::SQLite::d b prepare failed: attempt to prepare on inactive database handle"

        Comment

        Working...