"UPDATE WHERE `id` IN ($sql)"
$query = $DB->prepare("UPDATE `Ttopic` SET `main`=:main, `main_id`=:theme,`type`='".$f['type']."' WHERE `id` IN ($q) limit 10");
$query->bindParam(':main', $main);
$query->bindParam(':theme', $theme);
if($query->execute($Ar)) echo 'ok';
$inValues = [1, 2, 3, 4];
$inKeys = array_map(function($key){return ':var_'.$key;}, array_keys($inValues));
$sql = 'SELECT * FROM `table` WHERE `field` IN ('.implode(',', $inKeys).')';
echo $sql;
$db = new PDO(...);
$stmt = $db->prepare($sql);
foreach($inValues as $key=>$val) {
$stmt->bindParam(':var_'.$key, $val);
}
<?php
$inValues = [1,2,3,4];
$preparedInValues = array_combine(
array_map(function($key) {
return ':var_'.$key;
}, array_keys($inValues)),
array_values($inValues)
);
$sql = 'SELECT * FROM `table` WHERE `field` IN ('.implode(',', array_keys($preparedInValues)).')';
echo $sql;
$db = new PDO(...);
$stmt = $db->prepare($sql);
$stmt->execute($preparedInValues);
/* Execute a prepared statement using an array of values for an IN clause */
$params = array(1, 21, 63, 171);
/* Create a string for the parameter placeholders filled to the number of params */
$place_holders = implode(',', array_fill(0, count($params), '?'));
/*
This prepares the statement with enough unnamed placeholders for every value
in our $params array. The values of the $params array are then bound to the
placeholders in the prepared statement when the statement is executed.
This is not the same thing as using PDOStatement::bindParam() since this
requires a reference to the variable. PDOStatement::execute() only binds
by value instead.
*/
$sth = $dbh->prepare("SELECT id, name FROM contacts WHERE id IN ($place_holders)");
$sth->execute($params);
'WHERE id in (?,?,?,?,?,?,?)'
и собачить типизированные параметры
->bindParam(1, $id, PDO::PARAM_INT);
->bindParam(2, $id, PDO::PARAM_INT);
...
Но это за тебя сделает
вот эта штука
$place_holders = implode(',', array_fill(0, count($params), '?'));
насколько я понял.
$values = [1, 2, 3];
$in_query = implode(',', array_fill(0, count($values), '?'));
$query = $DB->prepare(sprintf("UPDATE `Ttopic` SET `main`= ?, `main_id`= ?, `type`='".$f['type']."' WHERE `id` IN (%s) LIMIT 10", $in_query));
if($query->execute(array_merge([$main, $theme], $values)) echo 'ok';
$stmt = false;//Требуется объявить так как передаётся в метод execute по ссылке
$params = array("ids"=>array(1,4,7));
$sql = "SELECT * FROM `users` WHERE `id` IN (:ids)";
nikolaevevgePDOIn::execute($pdo,$sql,$params,$stmt);