-1

I'm trying to make my SQL calls more secure and I encounter 2 ways of making prepared statements, I was wondering if there is any difference between them.

This is the Query:

$query = 
            "INSERT INTO companies
            VALUES(
                NULL, 
                :name,
                :assignation,
                :priority
                )";

1)

        $statement = $pdoDbInstance->prepare($query);

        $statement->bindValue(':name', $name);
        $statement->bindValue(':assignation', $assignation);
        $statement->bindValue(':priority', $priority);

        $result = $statement->execute();

2)

$statement = $pdoDbInstance->prepare($query);

$result = $statement->execute(array(":name" => $name, ":assignation" => $assignation, ":priority" => $priority));

Is there any significant difference between them????

Gabriel Matusevich
  • 3,835
  • 10
  • 39
  • 58

1 Answers1

2

According to https://stackoverflow.com/a/12392590/2124401, it is a matter of whether you need to enforce the datatype. Execute always passes strings, so if you want something different or a specific datatype, use bindValue or bindParam. Otherwise, they are just a matter of preference.

Community
  • 1
  • 1
jlemley
  • 533
  • 1
  • 4
  • 15