如何在Laravel中使用MySQL的DECODE函数?(How to use MySQL's DECODE function in Laravel?)
让我们假装,我有下面的表名为“table1”:
id encoded_data -------------------- 1 hkhgkj23h42 2 872dskksadh使用密码字符串“mypassword”,使用MySQL ENCODE函数对encoded_data列进行编码。
在MySQL中我会做这样的事情来获取解码数据:
SELECT DECODE(encoded_data, 'mypassword') AS decoded_data FROM table1 WHERE id = 1我怎么能在Laravel做同样的事情?
Let's pretend, I have the following table named "table1":
id encoded_data -------------------- 1 hkhgkj23h42 2 872dskksadhThe encoded_data column is encoded with the MySQL ENCODE function using the password string "mypassword".
In MySQL I would do something like this to get the decoded data:
SELECT DECODE(encoded_data, 'mypassword') AS decoded_data FROM table1 WHERE id = 1How can I do the same in Laravel?
最满意答案
你可以做这样的事情
DB::table('table1')->select(array(DB::raw("DECODE(encoded_data, 'mypassword') AS decoded_data"))) ->where('id', '=', 1)->first();you could do something like this
DB::table('table1')->select(array(DB::raw("DECODE(encoded_data, 'mypassword') AS decoded_data"))) ->where('id', '=', 1)->first();更多推荐
发布评论