参数名的前导冒号是否传递给PDOStatement :: bindParam()是可选的? [英] Is the leading colon for parameter names passed to PDOStatement::bindParam() optional?
问题描述
在将:name
形式的命名参数传递给 PDOStatement::bindParam()
时,不管是否使用前导冒号似乎都行得通.
即要么:
$statement->bindParam(':name', $var);
或者这个:
$statement->bindParam('name', $var);
似乎可以正常工作.
的文档参数
参数标识符.对于使用named的准备好的语句 占位符,这将是格式为:name的参数名称. 使用问号占位符的准备好的语句,这将是 参数的1分度位置.
这是否意味着可以将结肠排除在外?
不,由于文档中未提及此内容,因此我认为可以肯定地认为这种行为不受官方支持并且不应被依赖. /p>
但是,它实际上确实起作用了(至少在PHP 5.3.24中有效)-如果缺少冒号,则会在内部将其添加到参数中(PDOStatement::bindParam()
, it seems to work whether or not the leading colon is used.
i.e. either this:
$statement->bindParam(':name', $var);
or this:
$statement->bindParam('name', $var);
seems to work.
Here's the documentation for PDOStatement::bindParam()
parameter
Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form :name. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter.
Does this mean the colon can be left off?
No, since the documentation doesn't mention this I think it's safe to assume that this behaviour isn't officially supported and shouldn't be relied upon.
However, it does actually happen to work (in PHP 5.3.24 at least) - internally a colon will be added to the parameter if it's missing (see ext/pdo/pdo_stmt.c:363
in the PHP 5.3.24 source code).
这篇关于参数名的前导冒号是否传递给PDOStatement :: bindParam()是可选的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!