创建对象的问题?

创建对象的问题?

类中的方法:
function add()
{
$db=new database;
$sql="insert into computers(name,price,author) values ('$this->name','$this->price','$this->author')";
$db->connect();
$db->execute($sql);
$db=NULL;
}  
/**
*功能:更新数据
*参数:null
*返回值:null
*/
function update()
{
$db=new database;
$db->connect();
$sql="update computers set name='$this->name',price='$this->price',author='$this->author' where id=$this->id";
$db->execute($sql);
$db=NULL;
}
/**
*功能:删除数据
*参数:NUll
*返回值:null
*/
function delete()
{
$db=new database;
$db->connect();
$sql="delete from computers where id='$this->id'";
$db->execute($sql);
$db=NULL;
}
需要每个方法都new个对象吗?
有什么好的写法?

$db=new database;
function add()
{
global $db;
$sql="insert into computers(name,price,author) values ('$this->name','$this->price','$this->author')";
$db->connect();
$db->execute($sql);
}
如履薄冰