title: Fatal error: Uncaught Error: Call to a member function prepare()
body: <p>I would like to add information in the user session. I take this data from the db but I have always this error:</p>
  <pre><code>Fatal error: Uncaught Error: Call to a member function prepare() on null in /web/htdocs/-----/home/classes/functions.php:10 Stack trace: #0 /web/htdocs/------/home/classes/functions.php(25): Functions-&gt;getInformazioni(11) #1 /web/htdocs/------/home/profile.php(11): Functions-&gt;dropInformazioni(11) #2 {main} thrown in /web/htdocs/---------/home/classes/functions.php on line 10
  </code></pre>
  <p>I replace my site with &quot;-----&quot;.</p>
  <p>this is my code:
  profile.php</p>
  <pre><code>&lt;?php
  require(__DIR__.'/includes/config.php');
  $title = 'F&amp;S: Profilo';
  require(__DIR__.'/layout/head.php');
  
  //if not logged in redirect to login page
  if (! $user-&gt;is_logged_in()){
      header('Location: index.php');
      exit();
  }
  $function-&gt;dropInformazioni($_SESSION['memberID']);
  //include header template
  require(__DIR__.'/layout/header.php');
  ?&gt;
  &lt;div class=&quot;container&quot;&gt;
      &lt;div class=&quot;main-body&quot;&gt;
            &lt;div class=&quot;row gutters-sm&quot;&gt;
              &lt;div class=&quot;col-md-4 mb-3&quot;&gt;
                &lt;div class=&quot;card&quot;&gt;
                  &lt;div class=&quot;card-body&quot;&gt;
                    &lt;div class=&quot;d-flex flex-column align-items-center text-center&quot;&gt;
                      &lt;img class=&quot;img-res&quot; src=&quot;https://avatar.tobi.sh/&lt;?php echo $_SESSION['email'];?&gt;.svg?text=&lt;?php echo (substr($_SESSION['name'], 0, 1)); echo (substr($_SESSION['surname'], 0, 1));?&gt;&quot; width=&quot;150&quot;&gt;
                      &lt;div class=&quot;mt-3&quot;&gt;
                        &lt;h4&gt;&lt;?php echo $_SESSION['name']; ?&gt; &lt;?php echo $_SESSION['surname']; ?&gt;&lt;/h4&gt;
                      &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-md-8&quot;&gt;
                &lt;div class=&quot;card mb-3&quot;&gt;
                  &lt;div class=&quot;card-body&quot;&gt;
                    &lt;div class=&quot;row&quot;&gt;
                      &lt;div class=&quot;col-sm-3&quot;&gt;
                        &lt;h6 class=&quot;mb-0&quot;&gt;Full Name&lt;/h6&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;col-sm-9 text-secondary&quot;&gt;
                        Kenneth Valdez
                      &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;hr&gt;
                    &lt;div class=&quot;row&quot;&gt;
                      &lt;div class=&quot;col-sm-3&quot;&gt;
                        &lt;h6 class=&quot;mb-0&quot;&gt;Email&lt;/h6&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;col-sm-9 text-secondary&quot;&gt;
                        fip@jukmuh.al
                      &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;hr&gt;
                    &lt;div class=&quot;row&quot;&gt;
                      &lt;div class=&quot;col-sm-3&quot;&gt;
                        &lt;h6 class=&quot;mb-0&quot;&gt;Phone&lt;/h6&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;col-sm-9 text-secondary&quot;&gt;
                        (239) 816-9029
                      &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;hr&gt;
                    &lt;div class=&quot;row&quot;&gt;
                      &lt;div class=&quot;col-sm-3&quot;&gt;
                        &lt;h6 class=&quot;mb-0&quot;&gt;Mobile&lt;/h6&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;col-sm-9 text-secondary&quot;&gt;
                        (320) 380-4539
                      &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;hr&gt;
                    &lt;div class=&quot;row&quot;&gt;
                      &lt;div class=&quot;col-sm-3&quot;&gt;
                        &lt;h6 class=&quot;mb-0&quot;&gt;Address&lt;/h6&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;col-sm-9 text-secondary&quot;&gt;
                        Bay Area, San Francisco, CA
                      &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;hr&gt;
                    &lt;div class=&quot;row&quot;&gt;
                      &lt;div class=&quot;col-sm-12&quot;&gt;
                        &lt;a class=&quot;btn btn-info &quot; href=&quot;#&quot;&gt;Edit&lt;/a&gt;
                      &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
  
  
  
              &lt;/div&gt;
            &lt;/div&gt;
  &lt;?php
  require(__DIR__.'/layout/footer.php');
  ?&gt;
  </code></pre>
  <p>a part of functions.php</p>
  <pre><code>private function getInformazioni($id) {
        try {
          $stmt = $this-&gt;$_db-&gt;prepare('SELECT memberID, name, surname, comune, provincia, via, prefisso_int, telefono FROM members WHERE memberID = '.$id.' AND active=&quot;Yes&quot;');
          $stmt-&gt;execute(array('memberID' =&gt; $id));
          return $stmt-&gt;fetch();
        } catch (PDOException $e) {
          echo &quot;$e&quot;;
        }
  
  
      }
  
      public function dropInformazioni($id) {
        $row = $this-&gt;getInformazioni($id);
        $_SESSION['name'] = $row['name'];
        $_SESSION['surname'] = $row['surname'];
      }
  </code></pre>
  <p>If I put the code in the classes in to the profile.php the script work meanwhile if I use the php class it give to me the error in the title. I hope you can understand what I say.
  Sorry for my bad english.</p>