找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 75|回复: 1

Lavarel 输出带参数sql

[复制链接]

86

主题

84

回帖

728

积分

管理员

积分
728
发表于 2023-6-3 16:28:52 | 显示全部楼层 |阅读模式
  1. $where = [
  2.     'is_finance' => 2,
  3.     'status' => -2,
  4.     'refund_status' => 2,
  5.     'add_time' => 2,
  6.     ['add_time', '<', 123456789]
  7. ];
  8. $query = self::where($where);
  9. $sql = $query->toSql();
  10. $bindings = $query->getBindings();
  11. $results = $query->get();

  12. $full_sql = vsprintf(str_replace('?', '%s', $sql), collect($bindings)->map(function ($binding) {
  13.     return is_numeric($binding) ? $binding : "'{$binding}'";
  14. })->toArray());

  15. dd($full_sql, $results);
复制代码

86

主题

84

回帖

728

积分

管理员

积分
728
 楼主| 发表于 2023-8-4 15:11:06 | 显示全部楼层
         $sql = $obj_db->toSql();
            $bindings = $obj_db->getBindings();
           // $results = $obj_db->get();

            $full_sql = vsprintf(str_replace('?', '%s', $sql), collect($bindings)->map(function ($binding) {
                return is_numeric($binding) ? $binding : "'{$binding}'";
            })->toArray());

            dd($full_sql);
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Discuz! X

GMT+8, 2025-12-6 12:36 , Processed in 0.083272 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表