WordPress $wpdb no result

Your specific issue in that code is that you’re missing the quote marks around the $code.

$query .= 'WHERE code=".$code;

Should be:

$query .= "WHERE code= "'.$code.'"';

In the long run, you should indeed use prepare() properly, but this is the specific problem with the code you posted.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)