【发布时间】:2015-01-17 05:57:11
【问题描述】:
在 CakePHP3 中,有一个 ORM 可以帮助构建查询。
从documentation,我可以看到
$query = $articles->find(); // build a query that has not run yet
$query->where(['id' => 1]); // Return the same query object
所以在这种情况下,我想要字符串
WHERE `articles`.`id` = 1
经过一番谷歌搜索,我发现有一种方法to return just the where clause of a query object。
$query->where(['id' => 1])->clause('where'); // Return the where clause in the form of a QueryExpression
更多谷歌搜索让我了解如何get the QueryExpression to spit out string representation
$query->where(['id' => 1])->clause('where')->sql($valueBinder); // Return the where clause in string format
这是我的问题。我不知道 $valueBinder 应该是什么样子。不知道怎么初始化。
我也很高兴不使用 ValueBinder,只要我可以使用 CakePHP 3 ORM 和正确的 SQL 方言获得字符串格式的 where 子句。请假设我使用的是 MySQL。
请指教。
编辑
我尝试使用$query->valueBinder() 作为$valueBinder。
它是空的并且不包含关联的c:0 到值1。
【问题讨论】:
标签: php mysql cakephp orm cakephp-3.0