Reformatted a bit (a lot?) to help visualize what is being done. One problem was the use of a PHP array element (e.g. $user['id']
) within the double-quoted string, plus the closing out of that string. Maybe this at least gets you close?
// * Note wrapping of array element in braces within PHP string
// * Not sure about whether my balancing of parentheses is logically correct?
$sql = <<<EOD
SELECT id, public_note, type
FROM bans
WHERE ip = ? OR (
{$usr['id']} <> ? AND user_id = ? ) AND
( ban_end = ? OR ban_end > ? )
)
EOD; // must be no white-space at start of this line
// Now let's use that in the DB function with some formatting to help readability
$banchk = $db->run(
"$sql",
[
$usr['ip'],
'0',
$usr['id'],
'0',
$rightnow
]
)->fetch();