Trying to share the database handle between two processes like you are doing is just asking for trouble. The best solution would be to connect to the database after the fork, or at least have the child process reconnect to the database after the fork.
You also need to read up on what happens when the process forks, because with the example code you have posted, the next step after the fork is that both the parent and child process are going to attempt to drop the 'foo' table, and then they are both going to call waitpid, and then both attempt to disconnect from the database.