我正在使用Zend DB(v1)进行查询,但我找不到在查询中包含SUBSTR语句的方法,因为它有多个参数。
这就是我想要实现的目标:
SELECT *
FROM myTable
WHERE SUBSTR(myField, myVar1, myVar2) = 'xxx'
我需要使用Zend DB标准格式,但是当我需要将myField,myVar1,myVar2作为PHP变量($ myField,$ myVar1,$ myVar2)传递时,似乎不接受多个参数。 'xxx'在这里不是变量,是固定值。
$sql = $this->select()
->from(["t1" => "myTable"]])
->where( ... ); // Not sure how to implement this
有人知道如何实现这个目标吗?
答案 0 :(得分:0)
当然,只需写下来!
$sql = $this->select()
->from(["t1" => "myTable"]])
->where("SUBSTR(myField, myVar1, myVar2) = ?", 'XXX')
答案 1 :(得分:0)
经过一些尝试和错误后,我发现这种解决方法似乎有效:
$myFieldQuoted = $this->_db->quote($myField);
$myVar1Quoted = $this->_db->quote($myVar1);
$myVar2Quoted = $this->_db->quote($myVar2);
$sql = $this->select()
->from(["t1" => "myTable"]])
->where("SUBSTR($myFieldQuoted, $myVar1Quoted, $myVar2Quoted) = 'xxx'");