J
J
jazzman72020-02-28 01:39:30
PHP
jazzman7, 2020-02-28 01:39:30

What is the difference between execute and bindParam?

Good day. I started to translate the site from php 5.6 to 7, I make requests like this:

$user =  $pdo->prepare("SELECT * FROM `users` WHERE `login`=? AND `password`=?");
$user->execute(array($login,$password));


However, this method is rarely indicated in the documentation and bindParam is written. Why? What is the difference? How to write correctly? Google didn’t ban me, I read the documentation, but I still didn’t understand the difference.

If you can write as I write, is it necessary to write an array in execute? I have one variable in many places:
$count_sites = $pdo->prepare("SELECT * FROM `sait` WHERE `category` = ? AND `hosts` > '0' AND `status` = '1'");
$count_sites->execute(array($cat['id']));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sprashivatel, 2020-02-28
@jazzman7

execute puts all parameters into strings and a query, for example, to paginate a view

...(select bla-bla-bla limit ?, ?)->execute([1, 10])...

will not work, since 1 and 10 are strings and need to be bound to int

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question