Написал простенький класс для sql-запросов для php5 (в php4 будет ошибка). Применение:


    $o_sql=new Sql();
    $branch=$o_sql->get_array('SELECT object_id AS id, parent_id, auser_id FROM object');
    foreach($branch as $row){
        ...
        // код типа $row['имя_поля']
        ...
    }

    

Исходник:


class Sql
{
    public $dbname = 'area';
    public $host = 'localhost';
    public $user = 'root';
    public $password = '';
    public $charset = 'utf8';
    function void($query)
    {
        mysql_connect($this->host, $this->user, $this->password) or // mysql://root@localhost/
            die('Could not connect: ' . mysql_error());
        mysql_select_db($this->dbname);
        mysql_query("SET NAMES '".$this->charset."'");

        mysql_query($query);
    }
    function get_array($query)
    {
        // sql connect
        mysql_connect($this->host, $this->user, $this->password) or // mysql://root@localhost/
            die('Could not connect: ' . mysql_error());
        mysql_select_db($this->dbname);
        mysql_query("SET NAMES '".$this->charset."'");
        
        // take data
        $table=array();
        $sql=mysql_query($query);
        while($row=mysql_fetch_array($sql, MYSQL_ASSOC))
        {
            array_push($table,$row);
        }
        mysql_free_result($sql);
        return $table;
    }
}