dsfs64664 2014-02-25 15:08
浏览 29
已采纳

Laravel查询我的变量

Controller:

public function getSpecificPost($id)
{
    $returnArray = with(new Posts)->getSpecificPost($id);

    print_r($returnArray);
}
?>

Model:

public function getSpecificPost($post_id)
{
   //exit($post_id);
   return DB::table('posts')->where('id', $post_id)->toSql();
}
?>

If I uncomment the exit, it gives me a 1 as return. When I comment the exit I of course get a query, the query is as follows:

select * frompostswhereid= ?

Its Laravel Framework, help me out please!

  • 写回答

1条回答 默认 最新

  • dqask02082 2014-02-25 15:14
    关注

    The ? is a placeholder for your variable. It will be replaced with (in this case) 1. See the colored block on this page:

    Note: The Laravel query builder uses PDO parameter binding throughout to protect your application against SQL injection attacks. There is no need to clean strings being passed as bindings.

    You are aware of the fact that your don't actually execute the query? If you want to get the specific post with $post_id, you can change the line in your model to this one:

    return DB::table('posts')->where('id', $post_id)->first();
    

    If you want to see all executed queries (with replaced variables!) with Eloquent, you can use Laravel PHP Debugbar.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?