我的班级看起来像:
class MyDBClass extends SQLite3{
function __construct()
{
$this->open('/path_of_file');
}
public function saveArticle($product, $dbObject){
try{
$title = sqlite_escape_string(strip_tags($product['title']));
$productInsertQuery = "INSERT INTO Products (Title) VALUES (:title)";
$query = $dbObject->prepare($productInsertQuery);
$query->bindValue(':title', $title, SQLITE3_TEXT);
$result = $query->execute();
}
Catch(Exception $e){
echo $e->getMessage();
}
}
}
我称它为另一个类,如:
$this->dbObject->saveProduct($product, $this->dbObject);
如何避免在其起源的同一类中传递 $this->dbObject ,我可以传递任何引用或做其他事情吗?或者这样做可以吗?
提前致谢。