Differences between using ? and :param in prepare statement

前端 未结 3 1919
北荒
北荒 2021-02-06 03:05

Let\'s say I want to select records where Id = 30. Prepared statements allow two ways of binding parameters:

question marks

3条回答
  •  余生分开走
    2021-02-06 03:33

    This seesm to be more of a preference based question as there isn't a strict right or wrong answer.

    Personally I avoid ? as it's tightly tied to the order of parameters. Although theoretically you shouldn't be able to mess this up by adding or removing binding a single binding, it just seems like it's asking for trouble. It is (slightly) less work though.

    :name is more concise and is tightly bound to the identification of bindings, not arbitrarily to the order. It involves a (tiny) bit more work but it is much easier to debug, and less prone to mistakes.

    I prefer being (slightly) concise over writing (slightly) less code.

提交回复
热议问题