mysql query – how to escape apostrophe?

Use esc_html() when outputting a string value inside tags. Use esc_attr() when you’re outputting a string value inside an attribute="". If you’re outputting a URL, use esc_url() instead of those two.

if ($tenantsInfo) {
        foreach ($tenantsInfo as $tenant) { 
           echo "<h2>Welcome, " . esc_html( $tenant->tenant_name ) . "</h2>";
        }
}