Fatal Error, Class not found
<p>I have picked up this code from a tutorial and have edited it make it suitable for my needs.</p>

<pre><code>&lt;?php
//if we got something through $_POST
if (isset($_POST['search'])) {
    // here you would normally include some database connection
    include('config2.php');
    $db = new db();
    // never trust what user wrote! We must ALWAYS sanitize user input
    $word = mysql_real_escape_string($_POST['search']);
    // build your search query to the database
    $sql = "SELECT name FROM $tbl_name WHERE name LIKE '%" . $word . "%'";
    // get results
    $row = $db-&gt;select_list($sql);
    if(count($row)) {
        $end_result = '';
        foreach($row as $r) {
            $result         = $r['title'];
            // we will use this to bold the search word in result
            $bold           = '&lt;span class="found"&gt;' . $word . '&lt;/span&gt;';
            $end_result     .= '&lt;li&gt;' . str_ireplace($word, $bold, $result) . '&lt;/li&gt;';
        }
        echo $end_result;
    } else {
        echo '&lt;li&gt;No results found&lt;/li&gt;';
    }
}
?&gt;
</code></pre>

<p>I am getting this error when I run the code:</p>

<pre><code>Fatal error: Class 'db' not found in /home/peltdyou/public_html/do_search.php on line 6
</code></pre>

<p>I am very new to PHP so could anyone shed some light onto my problem..</p>

<p>UPDATE:</p>

<pre><code>&lt;?php   

    class db {

    function __construct()
    {
        global $dbh;
        if (!is_null($dbh)) return;
        $dbh = mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD);
        mysql_select_db(DB_NAME);
        mysql_query('SET NAMES utf8');
    }

    function select_list($query)
    {
        $q = mysql_query($query);
        if (!$q) return null;
        $ret = array();
        while ($row = mysql_fetch_array($q, MYSQL_ASSOC)) {
            array_push($ret, $row);
        }
        mysql_free_result($q);
        return $ret;
    }   
 } 
?&gt;
</code></pre>

<p>This is the db.php code.. I thought by replacing this with my own config2.php file I could get it to connect to my database.. Obviously not</p>
