in reply to alarm function not working here

Signals, including the alarm signal, will only interrupt Perl when it is safe to do so. It would not be safe to do so in the middle of your database driver's C code, so Perl waits for the driver to return first. If the infinite loop occurs in your database driver's C code, alarm will not help you without switching to unsafe signals. Timeout alarm for regex has some discussion on this subject.