PHP PDO添加过滤器到所有查询 [英] PHP PDO Add filter to all queries
问题描述
一个例子是租户字段(在一个multitenant分贝)。我想全局地添加这种类型的过滤器到所有的操作:
tenant = companyA
再一次。没有ORM,我已经知道如何用SQL Alquemy,Laravel的雄辩和主义来做到这一点。我现在想知道是否可能只是用PDO。
创建一个扩展 然后你可以使用你自己的方法 ($ params){ 您可以在自己的方法中应用您的过滤器... Is there a way, using JUST PHP PDO (No ORMs) to globally filter all fetch/insert/update/delete operations. One example is a tenant field (in a multitenant db). I would like to globally add this type of filter to all operations: tenant = companyA Once again. NO ORMs, I already know how to do it with SQL Alquemy, Laravel's eloquent and Doctrine. I now want to know if it's possible just with PDO. Create a class extending Normally i override the Then you can use your own methods Inside your own method you can apply your filters... 这篇关于PHP PDO添加过滤器到所有查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! PDO
like
class DB extends PDO {...
正常情况下,我重写 __ construct()
方法来获取任何文档中的数据库证书并连接到数据库,不要忘记调用这个方法父构造函数 parent :: __ construct()
...
...
$ stmt = $ this->准备('')...
$ rows = $ stmt-> fetch(PDO :: FETCH_ASSOC)...
}
PDO
likeclass DB extends PDO {...
__construct()
method to get database credentials inside any document and connect to database, don't forget to call on bottom of this method the parent constructor parent::__construct()
...public function find($params) {
...
$stmt = $this->prepare('')...
$rows = $stmt->fetch(PDO::FETCH_ASSOC)...
}