I don't know how to express the title. The approximate meaning is: how to add a comparison field query after the SQL statement query in thinkphp uses an array as the query condition. In the thinkphp manual, it is recommended to use Arrays for queries, which is highly secure. However, I encountered a problem. When we use Arrays for comparison
I don't know how to express the title. The approximate meaning is: how to add a comparison field query after the SQL statement query in thinkphp uses an array as the query condition. In the thinkphp manual, it is recommended to use Arrays for queries, which is highly secure. However, I encountered a problem. When we use Arrays for comparison
I don't know how to express the title. The approximate meaning is: how to add a comparison field query after the SQL statement query in thinkphp uses an array as the query condition.
In the thinkphp manual, it is recommended to use Arrays for queries, which is highly secure. However, I encountered a problem. When we compare fields in the array form, we cannot compare fields, which is depressing. The Code is as follows:
First, the SQL statement I need is like this.
select * from post where (id = '100') and (user_id = `user`.user_id)
This is the way TP uses arrays.
$sql = M('post')$map['id']??=?array('eq',100);$map['user_id']??=?array('eq','user.user_id');$sql->where($map)->$sql;
The SQL statement to survive is as follows:
select * from post where (id = '100') and (user_id = 'user.user_id')
The field comparison in the latter part is changed to a comparison string because the single quotation mark is added. Not the statement I want.
After reading thinkphp's official manual, no solution was found, and Google Baidu did not. Later, I had an opportunity to figure out whether the where statement can be repeatedly written twice? Change the code to the following:
$sql = M('post')$map['id']??=?array('eq',100);$sql->where($map)->where('user_id = user.user_id')->$sql;
Run $ SQL-> getlastsql (); print to obtain the following SQL:
select * from post where (id = '100') and (user_id = `user`.user_id)
Oh! This is the SQL statement I need. It seems that the where clause can be called repeatedly.
Finally, I spoke about the thinkphp manual, which was not mentioned in many of the above knowledge points. It looks really hard. Fortunately, this is worth the effort. Now thinkphp is quite comfortable.
Original article address: Comparison of fields in the array mixed with thinkphp complex query. Thank you for sharing it with the original author.