I made this function to give me a random string 5 characters long. It checks it against the database to confirm it is unique. I originally used this with the mysql_ functions, but switched to PDO for experience and for better programming. If you notice, i put in several echo's for debugging purposes.

When i run the code, it displays 12. It is stopping at my Try and not giving me any errors whatsoever. Any help?

PHP Code:
function generateURL() {
    
$length 5;
    
$characters '23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
    
$string "";    
    echo 
'1';
    for (
$p 0$p $length$p++) {
        
$string .= $characters[mt_rand(0strlen($characters))];
    }
    echo 
'2';
    try {
        
$STH $DBH->prepare("SELECT uniqueurl FROM links WHERE uniqueurl = :uniqueurl");
        
$STH->bindParam(':uniqueurl'$string);
        
$STH->execute();
        
$count $STH->columnCount();
    }
    catch(
PDOException $e) {  
        echo 
$e->getMessage() . "There was an error - Check Log";
        
file_put_contents('errlog.txt'$e->getMessage() . "\r\n"FILE_APPEND);  
    }
    echo 
'3';
    if (
$count == '0') {
        echo 
'4';
        return 
$string;
        
    } else {
        echo 
'5';
        
generateURL();
    }