I encountered a problem today, which is to query the data of vendor_id = vendor_f_id in the vendor table. In fact, it is very simple to use the native sql statement:
select * from vendor where vendor_id = vendor_f_id
But , in thinkphp, for the simplicity and versatility of the code, we do not consider using the native way to query sql, but use the query map method to query
$condition[ 'vendor_f_id' ] = 'vendor_id';
However, when thinkphp handles the above conditions, it will It is converted into the following code:
select * from vendor where vendor_f_id = 'vendor_id'
In other words, vendor_id is treated as a string
The solution to the above problem is:
$condition[ 'vendor_f_id' ] = [ 'exp' , ' = vendor_id ' ]
More ThinkPHP For related technical articles, please visit the ThinkPHP Tutorial column to learn!
The above is the detailed content of thinkphp exp usage. For more information, please follow other related articles on the PHP Chinese website!