title: why a fetch assoc return null in PDO PHP
body: <p>I'm trying to get the max value of a colunm in a table. I use PDO and PHP. I have created a function to do it. This function is:</p>
  <pre><code> function maximaPartida($link){
      try{
      $consulta = $link-&gt;prepare(&quot;select MAX(idPartida) as maxId from partidas&quot;);
      $consulta-&gt;execute();
      echo $consulta-&gt;getAttribute;
      $result = $consulta-&gt;fetch(PDO::FETCH_ASSOC);
  
      
  }catch (PDOException $e){
      $dato = &quot;¡Error!: &quot; . $e-&gt;getMessage() . &quot;&lt;br/&gt;&quot;;
      echo $dato;
      die();
   }  
  
  }
  </code></pre>
  <p>I call to this function of this way (crewating and object and calling the specific method) but when I do that it returns NULL.</p>
  <pre><code>$partida = new Partida();
  $id = $partida-&gt;maximaPartida($base-&gt;link);
  $partida-&gt;idPartida = $id['maxId'];
  </code></pre>
  <p>$id is NULL. Why it happen? What I can do?</p>