I have a Function which returns the "# of New Friend Requests" that a User has, and am not sure what to return in case that there is a problem with my query in the Function.
Here is my code...
PHP Code:function getNewFriendRequestCount($dbc, $requestee){
// Build query.
$q1 = "SELECT COUNT(requestor)
FROM friend
WHERE requestee=?
AND requestor_approved=1 AND requestee_approved=0";
// Prepare statement.
$stmt1 = mysqli_prepare($dbc, $q1);
// Bind variable to query.
mysqli_stmt_bind_param($stmt1, 'i', $requestee);
// Execute query.
mysqli_stmt_execute($stmt1);
// Store results.
mysqli_stmt_store_result($stmt1);
// Check # of Records Returned.
if (mysqli_stmt_num_rows($stmt1)!==1){
// Friend-Request Count Found.
// Bind result-set to variables.
mysqli_stmt_bind_result($stmt1, $newFriendRequestsCount);
// Fetch record.
mysqli_stmt_fetch($stmt1);
return $newFriendRequestsCount;
}else{
// Friend-Request Count Not Found.
$resultsCode = 'FUNCTION_FRIEND_REQUEST_COUNT_NOT_FOUND_5005';
// Set Source Page. (New)
$sourcePage = $_SERVER['SCRIPT_NAME'];
// Log Function Error.
logError($dbc, $resultsCode, $sourcePage, $requestee);
// End script.
// exit();
// IS THIS OKAY TO DO, OR SHOULD I DO SOMETHING ELSE??
return '';
}
}//End of getNewFriendRequestCount
Originally, I had this line of code after my IF-THEN-ELSE...
PHP Code:return $newFriendRequestsCount;
However, that caused an "Undefined Variable" error when the ELSE branch fired, so I moved things around, and just went with return '' for lack of a better idea?!
Suggestions?
Thanks,
Debbie




Reply With Quote




Bookmarks