Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用MySQL';Laravel中的s解码功能?_Php_Mysql_Laravel - Fatal编程技术网

Php 如何使用MySQL';Laravel中的s解码功能?

Php 如何使用MySQL';Laravel中的s解码功能?,php,mysql,laravel,Php,Mysql,Laravel,让我们假设,我有一个名为“table1”的表: 已编码的_数据列使用密码字符串“mypassword”进行编码 在MySQL中,我会这样做来获取解码数据: SELECT DECODE(encoded_data, 'mypassword') AS decoded_data FROM table1 WHERE id = 1 我怎样才能在拉威尔做到同样的事呢?你可以这样做 DB::table('table1')->select(array(DB::raw("DECODE(enc

让我们假设,我有一个名为“table1”的表:

已编码的_数据列使用密码字符串“mypassword”进行编码

在MySQL中,我会这样做来获取解码数据:

SELECT
  DECODE(encoded_data, 'mypassword') AS decoded_data
FROM
  table1
WHERE
  id = 1

我怎样才能在拉威尔做到同样的事呢?

你可以这样做

  DB::table('table1')->select(array(DB::raw("DECODE(encoded_data, 'mypassword') AS decoded_data")))
      ->where('id', '=', 1)->first();

谢谢它可以工作,但看起来很糟糕:)对于只检索值,而不是整行,我现在使用
  DB::table('table1')->select(array(DB::raw("DECODE(encoded_data, 'mypassword') AS decoded_data")))
      ->where('id', '=', 1)->first();