The difference between passing a data type and executing an array without them

I just want to know if these 2 sets of code do the same or not, if there is no difference?

$connect= new CONNECT(); $sql = ("query here"); $stmt = $connect->runQuery($sql); $stmt->bindParam(':sample', $_POST['sample'], PDO::PARAM_STR); $stmt->bindParam(':sample2', $_POST['sample2'], PDO::PARAM_STR); $stmt->bindParam(':sample3', $_POST['sample3'], PDO::PARAM_STR); $stmt->execute(); 

======================== And ======================== =

 $connect= new CONNECT(); $sql = ("query here"); $stmt = $connect->runQuery($sql); $stmt->execute(Array( ':sample1' => $_POST['sample'], ':sample2' => $_POST['sample2'], ':sample3' => $_POST['sample3'] )); 

FYI, both work just fine, just wanting to know if I get all the security benefits using one of them. Thanks.

+5
source share
1 answer

By $stmt->execute() parameters along with the $stmt->execute() method, all values ​​in array c are transferred as PDO::PARAM_STR to the operator using the $stmt->bindParam() function.

And with the $stmt->bindParam() function, you can determine the data type passed together with PDO::PARAM_*

Read more about PDO :: PARAM_

+5
source

Source: https://habr.com/ru/post/1272126/


All Articles