Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What the difference between bindParam and execute(array)?

Tags:

php

pdo

$stmt = $this->_db->prepare("SELECT userid FROM users WHERE login = ? AND md5pass = ?");
#$stmt->bindParam(1, $login, PDO::PARAM_INT);
#$stmt->bindParam(2, $pass, PDO::PARAM_STR);
$stmt->execute(array($login,$pass));
$res = $stmt->fetch(PDO::FETCH_NUM);

Which way is better to transfer variables to prepeared statment bindParam or execute(array)? Both working but what is differense? Only PDO::PARAM checking? For SELECT I think array would be enough and for INSERT I sould use the bindParam. Am I right? Thanks to all. Just learning =)

like image 647
user2062756 Avatar asked Dec 29 '25 18:12

user2062756


1 Answers

With bindParam you can add the datatype and also important with bind param you are binding the variables by reference.

like image 191
PeeHaa Avatar answered Jan 01 '26 07:01

PeeHaa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!