title: Cannot store database connection inside the $_SESSION
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2125403/cant-pass-mysqli-connection-in-session-in-php">Can&#39;t pass mysqli connection in session in php</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying to store a custom-made PHP MySql class into the $_SESSION. When accessed, PHP throws an error saying: "The script tried to execute a method or access a property of an incomplete object ... ". </p>
  
  <pre><code>include_once 'core/mysql.php';
  
      $conn = new mysql();
      $_SESSION['DBCONNECTION'] = new mysql();
  
      $result = $_SESSION['DBCONNECTION']-&gt;query_cust($sql);  // Fails!
      $result = $conn-&gt;query_cust($sql); // Works!
  </code></pre>
  
  <p>I'm just tying to understand how the Sessions in PHP work and what makes the difference between defining the class as a normal variable and a variable inside <code>$_SESSION</code> !?</p>
  
  <p><code>var_dump($_SESSION['DBCONNECTION'])</code> returns:</p>
  
  <pre><code>object(__PHP_Incomplete_Class)[1]
    public '__PHP_Incomplete_Class_Name' =&gt; string 'mysql' (length=5)
    public 'con' =&gt; int 0
  </code></pre>