douze1332 2017-04-29 10:05
浏览 43
已采纳

如何在PHP应用程序中正确评论数据库查询?

I am abslutly new in PHP and probably this is a very trivial question about how to correctly comment a line in a MySql query.

I have a query like this:

$query_hotel= "
    SELECT 
        hotel_name,
        hotel_id,
        room_id,
        ...................................
        ...................................
        ...................................
        FROM (
            ............................................
            ............................................
            )
            WHERE
                ...............................................
            HAVING
                //SUM(rate.price) BETWEEN ".$price_min." AND ".$price_max."
                SUM(rate.price) BETWEEN ".$min_price." AND ".$max_price."

    ................................................................................
    ................................................................................
    ................................................................................

So, as you can see in my code, I have to comment (to disable) this line:

//SUM(rate.price) BETWEEN ".$price_min." AND ".$price_max."

that have to be replaced by this line:

SUM(rate.price) BETWEEN ".$min_price." AND ".$max_price."

I am not sure that using the // at the line start it's correct. I also tried to do:

<!--SUM(rate.price) BETWEEN ".$price_min." AND ".$price_max."-->

but doing in this way my IDE (PHP Storm) is as disabled all but not the PHP variable.

So what is the correct way to do it without remove this line from my code? (I want to keep track of this changes and let it commented in my code)

  • 写回答

1条回答 默认 最新

  • dorv56831 2017-04-29 11:13
    关注

    SQL has two kinds of comments. A one-line comment uses the prefix --. You can also create a block comment by surrounding it with /* and */.

    MySQL also allows # as a comment prefix, this is an extension to the SQL standard.

    $query_hotel= "
        SELECT 
            hotel_name,
            hotel_id,
            room_id,
            ...................................
            ...................................
            ...................................
            FROM (
                ............................................
                ............................................
                )
                WHERE
                    ...............................................
                HAVING
                    /* SUM(rate.price) BETWEEN ".$price_min." AND ".$price_max." */
                    SUM(rate.price) BETWEEN ".$min_price." AND ".$max_price."
    
        ................................................................................
        ................................................................................
        ................................................................................
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点