pdo too many connection, suggestion
<p>this is my php code. problem is db connection and db close. i have too many connection error. i used <strong>$db = null;</strong> but i have again error. what can i do?
thank you...</p>

<p>db.php</p>

<pre><code>    public function getConnection(){

        $this-&gt;conn = null;

        try{
            $this-&gt;conn = new PDO("mysql:host=" . $this-&gt;host . ";dbname=" . $this-&gt;db_name .";charset=utf8", $this-&gt;username, $this-&gt;password); 
        }

        catch(PDOException $exception){
            echo "Connection error: " . $exception-&gt;getMessage();
        }

        return $this-&gt;conn;
    }
}


$database = new Config();
$db = $database-&gt;getConnection();
</code></pre>

<p>data.inc.php</p>

<pre><code>include 'db.php';

private $table_name = "contents";

public function __construct($db){
        $this-&gt;conn = $db;      
    }

function dbclose() { 

    $this-&gt;conn = null;

    return true;
    }

      function readContents($page, $from_record_num, $records_per_page,$category){


            $query = "SELECT 
                    *
                FROM 
                    " . $this-&gt;table_name . " where cat_id = ?
                ORDER BY 
                date desc 
                LIMIT 
                    {$from_record_num}, {$records_per_page}";

        $stmt = $this-&gt;conn-&gt;prepare( $query );
        $stmt-&gt;bindParam(1, $cat_id);
        $stmt-&gt;execute();

        return $stmt;
    }
</code></pre>

<p>index.php</p>

<pre><code>    $stmt1 = $product-&gt;readContents(1, 0, 20, 1); //page,0,20 list contents,category 1
    $stmt2 = $product-&gt;readContents(1, 0, 20, 5); //page,0,20 list contents,category 5
    $stmt3 = $product-&gt;readContents(1, 0, 20, 13); //page,0,20 list contents,category 13

while ($row1 = $stmt1-&gt;fetch(PDO::FETCH_ASSOC)){ //20 contents in category 1 }
while ($row2 = $stmt2-&gt;fetch(PDO::FETCH_ASSOC)){ //20 contents in category 5 }
while ($row3 = $stmt3-&gt;fetch(PDO::FETCH_ASSOC)){ //20 contents in category 13 }

$product-&gt;dbclose();
</code></pre>

<p>i used <strong>$db null;</strong> but, i have again too many connection error.  What can i do ? </p>