Below is a Function that I just created which returns a Section's Name...
I am wondering if I should return a NULL or '' in the ELSE branch in addition to logging the Error?PHP Code:function getSectionName($dbc, $slug){
// Build query.
$q1 = "SELECT name
FROM section
WHERE slug=?";
// Prepare statement.
$stmt1 = mysqli_prepare($dbc, $q1);
// Bind variable to query.
mysqli_stmt_bind_param($stmt1, 's', $slug);
// Execute query.
mysqli_stmt_execute($stmt1);
// Store results.
mysqli_stmt_store_result($stmt1);
// Check # of Records Returned.
if (mysqli_stmt_num_rows($stmt1)==1){
// Section Found.
// Bind result-set to variables.
mysqli_stmt_bind_result($stmt1, $sectionName);
// Fetch record.
mysqli_stmt_fetch($stmt1);
// Return Section Name.
return $sectionName;
}else{
// Section Not Found.
$resultsCode = 'FUNCTION_SECTION_NOT_FOUND_5010';
// Set Error Source.
$errorPage = $_SERVER['SCRIPT_NAME'];
// Log Function Error.
logError($dbc, $resultsCode, $errorPage);
// End script.
exit();
}//End of CHECK FOR SECTION
}
If I don't do that, then in my calling script, I would have to check for a Null like this to avoid an error...
...which seems silly.PHP Code:<title><?php echo (isset ($sectionName) ? $sectionName : '') ?> Section</title>
Suggestions?
Thanks,
Debbie




Reply With Quote
Bookmarks