$row = $cnt->prepare('UPDATE users SET size = $size WHERE login = ?');
$row->bindParam(1, $login);
$row->execute();
$row = $cnt->prepare('UPDATE users SET size = $size WHERE login = ?');
$row->bindParam(1, $login);
$row->execute();
echo '<pre>',print_r($var, 1);die;
$login = 'Login';или
$row = $cnt->prepare('UPDATE users SET size = $size WHERE login = ?');
$row->bindParam($login);
$row->execute();
$login = 'Login';
$size = 4;
$row = $cnt->prepare('UPDATE users SET size = ? WHERE login = ?');
$row->bindParam($size, $login);
$row->execute();
$row = $cnt->prepare('UPDATE `users` SET `size` = :size WHERE `login` = :login');
$row->execute([':size' => $size, ':login' => $login]);
echo '<pre>',print_r($var, 1);die;
$row = $cnt->prepare('UPDATE `users` SET `size` = :size WHERE `login` = :login');
$row->execute([':size' => $size, ':login' => $login]);
$login = 'Login';
$size = 4;
$row = $cnt->prepare('UPDATE users SET size = ? WHERE login = ?');
$row->bindParam($size, $login);
$row->execute();
Цитата |
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in /var/www/--------/data/www/--------/--------.php:56 Stack trace: #0 /var/www/--------/data/www/--------/--------.php(56): PDOStatement->execute() #1 {main} thrown in /var/www/--------/data/www/--------/--------.php on line 56 |
Цитата (maax @ 5.09.2015 - 15:06) |
а вот этот уже выдает ошибку |
$login = 'Login';
$size = 4;
$row = $cnt->prepare('UPDATE users SET size = ? WHERE login = ?');
$row->bindParam($size, $login);
$row = $cnt->prepare('UPDATE users SET size = ? WHERE login = ?');
$row->execute([$size, $login]);
Цитата (maax @ 6.09.2015 - 00:19) |
Так что же все таки лучше использовать bindParam ? или сразу через execute ?? |