|
-
Aug 27th, 2011, 01:32 AM
#1
Thread Starter
WiggleWiggle
[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(0, strlen($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(); } }
-
Aug 27th, 2011, 02:21 AM
#2
Thread Starter
WiggleWiggle
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|