我使用NOTORM生成查询,在应用程序中有一个案例,用户可以选择字段,条件等,因此基本上可以提出自定义查询。这样,用户就可以生成一个报告,例如“有名字的人=杰克已经花了> 800' 。
我使用NOTORM生成此查询,但我想将查询存储为不使用NOTORM的应用程序的其他部分使用。是否有任何函数来检索生成的查询?
这是生成并执行查询后NOTORM对象的查看方式:
object(NotORM_Result)#55 (33) {
["single":protected]=>
bool(false)
["select":protected]=>
array(0) {
}
["conditions":protected]=>
array(7) {
[0]=>
string(9) "name = ? "
[1]=>
string(12) "surname = ? "
[2]=>
string(15) "custom_field_19"
[3]=>
string(31) "custom_field_20 BETWEEN ? AND ?"
[4]=>
string(21) "custom_field_18 <= ? "
[5]=>
string(15) "custom_field_16"
[6]=>
string(10) "email = ? "
}
["where":protected]=>
array(7) {
[0]=>
string(9) "name = ? "
[1]=>
string(12) "surname = ? "
[2]=>
string(52) "custom_field_19 IN ('Yes', 'Sent lender info', 'No')"
[3]=>
string(31) "custom_field_20 BETWEEN ? AND ?"
[4]=>
string(21) "custom_field_18 <= ? "
[5]=>
string(28) "custom_field_16 IN ('Buyer')"
[6]=>
string(10) "email = ? "
}
["parameters":protected]=>
array(6) {
[0]=>
string(1) "a"
[1]=>
string(6) "Franco"
[2]=>
int(1218146400)
[3]=>
int(1249682400)
[4]=>
string(3) "800"
[5]=>
string(1) "?"
}
["order":protected]=>
array(0) {
}
["limit":protected]=>
NULL
["offset":protected]=>
NULL
["group":protected]=>
string(0) ""
["having":protected]=>
string(0) ""
["lock":protected]=>
NULL
["union":protected]=>
array(0) {
}
["unionOrder":protected]=>
array(0) {
}
["unionLimit":protected]=>
NULL
["unionOffset":protected]=>
NULL
["data":protected]=>
NULL
["referencing":protected]=>
array(0) {
}
["aggregation":protected]=>
array(0) {
}
["accessed":protected]=>
NULL
["access":protected]=>
NULL
["keys":protected]=>
array(0) {
}
["connection":protected]=>
NULL
["driver":protected]=>
NULL
["structure":protected]=>
NULL
["cache":protected]=>
NULL
["notORM":protected]=>
object(NotORM)#3 (12) {
["connection":protected]=>
object(PDO)#2 (0) {
}
["driver":protected]=>
string(5) "mysql"
["structure":protected]=>
object(NotORM_Structure_Convention)#4 (4) {
["primary":protected]=>
string(2) "id"
["foreign":protected]=>
string(5) "%s_id"
["table":protected]=>
string(2) "%s"
["prefix":protected]=>
string(0) ""
}
["cache":protected]=>
NULL
["notORM":protected]=>
NULL
["table":protected]=>
NULL
["primary":protected]=>
NULL
["rows":protected]=>
NULL
["referenced":protected]=>
array(0) {
}
["debug":protected]=>
bool(false)
["freeze":protected]=>
bool(false)
["rowClass":protected]=>
string(10) "NotORM_Row"
}
["table":protected]=>
string(5) "users"
["primary":protected]=>
string(2) "id"
["rows":protected]=>
NULL
["referenced":protected]=>
array(0) {
}
["debug":protected]=>
bool(false)
["freeze":protected]=>
bool(false)
["rowClass":protected]=>
string(10) "NotORM_Row"
}
我可以做某种迭代'where'和'parameters'的脚本,但似乎不太优雅,特别是因为那些数组的顺序不正确(我必须做一些事情,比如替换每个“?”) “参数”中的下一项)...任何NOTORM功能?或者你建议的更优雅的方式?
这是'where'和'parameters'部分,以防你为最后一个选项提供优雅的东西:
["where":protected]=>
array(7) {
[0]=>
string(9) "name = ? "
[1]=>
string(12) "surname = ? "
[2]=>
string(52) "custom_field_19 IN ('Yes', 'Sent lender info', 'No')"
[3]=>
string(31) "custom_field_20 BETWEEN ? AND ?"
[4]=>
string(21) "custom_field_18 <= ? "
[5]=>
string(28) "custom_field_16 IN ('Buyer')"
[6]=>
string(10) "email = ? "
}
["parameters":protected]=>
array(6) {
[0]=>
string(1) "a"
[1]=>
string(6) "Franco"
[2]=>
int(1218146400)
[3]=>
int(1249682400)
[4]=>
string(3) "800"
[5]=>
string(1) "?"
}
答案 0 :(得分:0)
只需将NotORM_Result对象转换为字符串
即可$sql = (string)$result;
//or
$sql = $result->__toString();