PDO Connection: Call to a member function prepare() on null
<p>Hello i have a question PDO connection. My conn.php is</p>

<pre><code>&lt;?php
define('host', 'localhost');
define('host_user', 'root');
define('host_pass', '');
define('host_db', 'testdb');
class Database {
public $conn;
public function Connect() {
try {
$conn = new PDO("mysql:host=" . host . ";dbname=" . host_db, host_user, host_pass, array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET NAMES utf8"));
$conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "Connection error:" . $e-&gt;getMessage();
}
}
}
?&gt;
</code></pre>

<p>When i use this</p>

<pre><code>$dbClass = new Database();
$stmt = $dbClass::Connect()-&gt;prepare("SELECT * FROM user_posts");
</code></pre>

<p>it returns following <strong>error:</strong></p>

<blockquote>
  <p>Call to a member function prepare() on null</p>
</blockquote>

<p>Why is it happen?</p>