title: How to fetch data from database using prepare statement in php?
body: <p>I have a database in which I have <code>user_id</code> &amp; <code>associated_id</code>.There can be multiple <code>associated_id</code> for a single <code>user_id</code>. Now I want to fetch all the <code>associated_id</code>s into a single array. I have tried this method but don't know how to get them in array.</p>
  
  <pre><code>$stmt = $this-&gt;conn-&gt;prepare("SELECT * FROM my_contacts WHERE user_id = ?");
  $stmt-&gt;bind_param("s", $user_id);
  if ($stmt-&gt;execute())
      {
          while ($stmt-&gt;fetch())
          {
              //what  to write here 
  
          }
  
  
          //echo var_dump($user);
          $stmt-&gt;close();
  
      }
  </code></pre>