functions from mysql to PDO
Posted: Wed Apr 02, 2014 7:08 am
I am trying to convert from MySQL to PDO and when I add the trigger on the page to call the function that page is 500 server error. What am I doing wrong with this
here is the orginal code
Here is what I have now
I know I have a lot to learn for pdo but any help and guiding would be great
here is the orginal code
Code: Select all
function generateTicketId ()
{
$ret = 0;
// Start a loop that will go on forever (until we exit it with `return` or `break;`)
while ( true )
{
// Generate random number from 11111 to 99999
$ret = rand ( 11111, 99999 );
// See if this number is being used
$result = mysql_query ( "SELECT count(*) FROM members WHERE acct_num='$ret' LIMIT 1") or die ( mysql_error () );
// Get the result
$row = mysql_fetch_row ( $result );
// If the query returned 0 records with this ticket Id, then it doesn't exist; return with the random number
if ( $row[0] == 0 || !is_array ( $row ) )
{
return $ret;
}
}
}
//use this to call the function
$ticketId = generateTicketId();
Here is what I have now
Code: Select all
function generateTicketId ()
{
$ret = 0;
// Start a loop that will go on forever (until we exit it with `return` or `break;`)
while ( true )
{
// Generate random number from 11111 to 99999
$ret = rand ( 11111, 99999 );
// See if this number is being used
$result = $conn->query('SELECT count(*) FROM users WHERE acct_id=$ret LIMIT 1');
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
//$result = mysql_query ( "SELECT count(*) FROM users WHERE acct_id='$ret' LIMIT 1") or die ( mysql_error () );
// Get the result
$row = mysql_fetch_row ( $result );
// If the query returned 0 records with this ticket Id, then it doesn't exist; return with the random number
if ( $row[0] == 0 || !is_array ( $row ) )
{
return $ret;
}
}
}