function not written right

I need to fine tune this function if the conditions in the where clause are true. I’m new at functions so this should be easy for those of you who know them well…Ultimately, if the statement is true, I need it to execute a call to yet another function.

function get_log_contentaging( $user_id, $ref , $ref_id = null ) {

global $wpdb, $logsource;
$request = "SELECT creds FROM {$logsource->log_table} WHERE user_id = '$user_id' AND ref= 'published_content' AND time > strtotime('-2 day', time())";

if ( ! empty( $ref_id ) ) {
    $request .= " AND ref_id = '$ref_id'";
}

return $wpdb->get_var( $request );}/* if the select statement for the user ID is true, then execute this- new Controller({'minDelay':3000, 'minCount':2, 'maxCount':25, 'mouseOver':'fly'});*/