PDO statements with named parameters VS question mark parameters

后端 未结 3 1147
闹比i
闹比i 2021-01-23 16:43

I have a class for database management, and one of my sub-classes (the one that defines a query) is defined like this (just a sample, many other functions are actually stripped

3条回答
  •  北海茫月
    2021-01-23 17:13

    Although there is no technical difference (as PDO will just replace named placeholders to question marks internally), there is a usability issue

    For the sprintf-like function question marks seems a lot better solution. As they will let you to use indeed sprintf-style (dunno why you're creating a whole class for the query):

    $query = new Query("SELECT * FROM t WHERE a=? AND b=?", $ida, $idb);
    

    while with named it will be a lot more verbose

提交回复
热议问题