PHP PDO, what is the practical difference in parameter sending?

Asked

Viewed 23 times

0

I’m having a question using the pdo in the php, there is some practical difference in implementation using these two approaches?

$db = new PDO("ok");
$sql = "INSERT INTO tabela (campo1, campo2) VALUES (:campo1, :campo2)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':campo1', "campo1", PDO::PARAM_STR);       
$stmt->bindParam(':campo2', "campo2", PDO::PARAM_STR); 
$stmt->execute();

$sql = "INSERT INTO tabela (campo1, campo2) VALUES (?, ?)"
$stmt = $db->prepare($sql);
$stmt ->execute(array("campo1","campo2");

I’ve always seen tutorials and examples using both approaches, but I never really knew what the difference was....

And there is still the parameter passage using the bindValue. Are any of them safer? What influence? Performance? Or are there any more recommended?

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.