如何在Laravel中使用MySQL的DECODE函数?(How to use MySQL's DECODE function in Laravel?)

编程入门 行业动态 更新时间:2024-10-28 07:20:59
如何在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 872dskksadh

The 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 = 1

How 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();

更多推荐

本文发布于:2023-08-05 14:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1434118.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   如何在   Laravel   MySQL   DECODE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!