saharabear
V2EX  ›  PHP

在PHP中怎么写SQL更方便符合不超过80列的规范?

  •  
  •   saharabear · Feb 12, 2013 · 4181 views
    This topic created in 4864 days ago, the information mentioned may be changed or developed.
    PHP虽然支持$str=<<<SQL(换行)(行首)SQL;的方式来编写多行,但这样结束符并不缩进,感觉上并不好,也不美观。

    如果使用连接符,在修改SQL的时候又会有问题。

    毕竟SQL还是经常超过几百个字符的。

    有什么好办法写SQL来尽量符合80列规范?
    4 replies    1970-01-01 08:00:00 +08:00
    xuwenhao
        1
    xuwenhao  
       Feb 12, 2013
    直接回车
    salforis
        2
    salforis  
       Feb 12, 2013
    超过几百字的SQL,只能说明你的DB很辛苦。
    m4ker
        3
    m4ker  
       Feb 12, 2013
    $sql = "
    select x.xx,x.xx
    from xxx x,xxx x
    where xxx=xxx
    __and xxx=xxx
    ___or xxx=xxx
    order by id desc
    limit a,b
    ";

    缩紧自理。
    saharabear
        4
    saharabear  
    OP
       Feb 13, 2013
    @xuwenhao
    @m4ker

    看来只好这样了,自己搞缩进。


    @salforis
    一个sql几百个单词也正常吧?随便两个表的连接,每个表三四十个字段,两表或者三表的连接,就要定义出一些东西。没办法,项目特色。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5992 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 03:27 · PVG 11:27 · LAX 20:27 · JFK 23:27
    ♥ Do have faith in what you're doing.