How should I get data from the node table? I am creating a Drupal Dashboard (PHP 7.2, Drupal 8.9). I'm trying to query the node table using the following code.
$database = \Drupal::database();

$query = $database-&gt;query(&quot;SELECT field_advertiser_id_value FROM {node__field_advertiser_id} WHERE entity_id = :entity_id&quot;, [
    ':entity_id' =&gt; $entity_id
]);

$result = $query-&gt;execute();
print_r($result);

I am not sure why $query-&gt;execute() returns false. This table exists in the l database.
The database contains both the node and the node__field_advertiser_id tables.

Inserting data in the node__field_advertiser_id works correctly.
$database = \Drupal::database();

$database-&gt;insert('node__field_advertiser_id')
    -&gt;fields([
      'entity_id' =&gt; $advertiser_nid,
      'revision_id' =&gt; 1,
      'delta' =&gt; 0,
      'field_advertiser_id_value' =&gt; $advertiser_id
    ])
    -&gt;execute();

I am trying to fetch details from the node__field_advertiser_id from hook_node_delete(). The data is still there in the table when I try to run the SQL query.
It would be great if anyone can help me out with this.
I don't think you need an execute on a regular query like that. But the way to get any node data would be loading the node with the entityTypeManager service, and getting the field values with $node-&gt;get('field_advertiser_id')-&gt;getValue(). Its rare to have to get a value that way from the database.
The same goes for the insert or update - you definitely should be using the API for this and not direct database writes.
On top of that you don't need to do anything with the database at all in this example, because the node being deleted is already passed to this hook. Just look at its field values. https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/function/hook_entity_delete/9.1.x
But in a case like this, hook_entity_delete may be too late to get values depending on what you need to do. Instead, you probably want to use hook_entity_predelete: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/function/hook_entity_predelete/9.1.x
Example:
function mymodule_entity_predelete(Drupal\Core\Entity\EntityInterface $entity) {
  if ($entity instanceof NodeInterface &amp;&amp; $entity-&gt;getType() == 'your_content_type') {
    $advertiser_id = $entity-&gt;get('field_advertiser_id')-&gt;first()-&gt;getValue();
    
    // do something with id, like load that node
    if (isset($advertiser_id)) {
      $entityTypeManager = \Drupal::entityTypeManager();
      $advertiser = $entityTypeManager-&gt;getStorage('node')-&gt;load($advertiser_id);
      
      if ($advertiser instanceof NodeInterface &amp;&amp; $entity-&gt;getType() == 'advertiser_content_type') {
        // Delete this other node.
        $advertiser-&gt;delete();
      }
    }
  }
}

You have to be careful with these hooks though, because it can trigger an infinite loop since these hooks are fired every time the actions are performed. Meaning, if you wanted to delete the advertiser node here for example, this hook would get called on that action too. So you need to be specific with your conditions check each value and logic. People get caught in presave hooks all the time.