Error Warning: mysql_fetch_assoc() in php
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/795746/warning-mysql-fetch-array-supplied-argument-is-not-a-valid-mysql-result">Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result</a>  </p>
</blockquote>



<p>In db.php I have:</p>

<pre><code>&lt;?php
class connect {

    private $host = "localhost";
    private $user = "root";
    private $pass = "";
    private $database = "databasename";
    private $connect = null;

    function connect() {
        $this-&gt;connect = mysql_connect($this-&gt;host, $this-&gt;user, $this-&gt;pass) or die("Can't connect database");
        mysql_select_db($this-&gt;database, $this-&gt;connect);
    }

    function getData() {
        $data = array();
        $sql = 'Select * From test';
        $query = mysql_query($sql);
        while($row = mysql_fetch_assoc($query)) {
            $data[] = array($row['id'], $row['name']);
        }
        return $data;
    }

}
?&gt;
</code></pre>

<p>In index.php I have:</p>

<pre><code>&lt;?php
include 'db.php';
$connect = new connect();
$connect-&gt;connect();
$data = $connect-&gt;getData();
$str = '';
foreach ($data as $dt) {
    $str .= $dt[1];
}
echo $str;
?&gt;
</code></pre>

<p>I am getting the following error:
=> <code>error: &lt;b&gt;Warning&lt;/b&gt;:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource</code> from db.php.</p>

<p>What am I doing wrong?</p>
