The choice of $
as the positional placeholder character within a PHP N1QL is completely baffling. Of ALL characters available, by far the WORST choice for the placeholder is $
because $
is reserved by PHP to delimit a variable. As such, $
is literally the ONLY character that absolutely should NOT have been chosen. ANY other special character would have been a better choice.
Constructing a N1QL statement that contains both a positional placeholder AND a PHP variable (which constitutes the bulk of the queries I write) is now heavily bogged down by escaping and chunking work that makes even simple dynamic queries difficult to read and highly error prone.
$name = $_GET['name'];
$n1ql = "SELECT * FROM bucket WHERE type=$1 AND name=$name "; //interpolation error $1 treated like a var
$n1ql = 'SELECT * FROM bucket WHERE type=$1 AND name=' . $name; //inconvenient, unnecessary, easy to forget
$n1sql = "SELECT * FROM bucket WHERE type=\$1 AND name=$name"; //also inconvenient and easy to forget!
What a mess. All because the PHP SDK falsely assumed it could use the ONE character it absolutely should NOT have used to delimit a positional placeholder within a N1QL string.
Why not use ^
as the placeholder parameter instead?
$n1ql = "SELECT * FROM bucket WHERE type=^1 AND name=$name"; //no problem, easy to type, easy to escape, easy to read!
Please change this!