1

I'm adding [] this symbol within an execute() in PDO, and it returns error.

I'm working in WAMP5

 $sqlStatement="
  SELECT * 
  FROM $table_results 
  WHERE title = ? AND id_category = ?
  ";    

   $stmt = $bdConection->prepare($sqlStatement);
   $stmt->execute([$title, $id_category]);
   echo $stmt->rowCount();

It works well if I delete WHERE title = ? AND id_category = ? and [$title, $id_category] bur returns more results, instead of adding those ... then IT RETURNS:

Parse error: syntax error, unexpected '[', expecting ')' in

Zhorov
  • 28,486
  • 6
  • 27
  • 52
joe
  • 25
  • 3

1 Answers1

1

I can reproduce this error with PHP 5.2. Documentation about PHP array's syntax states:

... As of PHP 5.4 you can also use the short array syntax, which replaces array() with []. ...

What you can do in your case is to define an array using array():

<?php

$sqlStatement = "
  SELECT * 
  FROM $table_results 
  WHERE title = ? AND id_category = ?
";    

...
$stmt = $bdConection->prepare($sqlStatement);
$stmt->execute(array($title, $id_category));
echo $stmt->rowCount();
...

?>
Zhorov
  • 28,486
  • 6
  • 27
  • 52