Results 1 to 2 of 2

Thread: [RESOLVED] PDO Problems...

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Resolved [RESOLVED] PDO Problems...

    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();
        }
        


  2. #2

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PDO Problems...

    Figured it out. I need to pass the $DBH variable to the function...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width