In {code...}, only 678689287 exists, and the returned result is null. If 678689287 is placed first, a result is returned. Is it a bug?
$user='test';$pass='123456';$dbh = new PDO('mysql:host=127.0.0.1;dbname=test', $user, $pass);$sth = $dbh->prepare("SELECT * FROM user WHERE id IN (?) ORDER BY id ASC");$sth->execute(['456089015, 456089016, 456089017, 456089018, 456089019, 456089020, 456089021, 456089022, 456089023, 456089024, 456089025, 678689287']);$result = $sth->fetchAll();print_r($result);
Only 678689287 exists, and the returned result is null. If 678689287 is put first, a result is returned.
Is it a bug?
Reply content:
$user='test';$pass='123456';$dbh = new PDO('mysql:host=127.0.0.1;dbname=test', $user, $pass);$sth = $dbh->prepare("SELECT * FROM user WHERE id IN (?) ORDER BY id ASC");$sth->execute(['456089015, 456089016, 456089017, 456089018, 456089019, 456089020, 456089021, 456089022, 456089023, 456089024, 456089025, 678689287']);$result = $sth->fetchAll();print_r($result);
Only 678689287 exists, and the returned result is null. If 678689287 is put first, a result is returned.
Is it a bug?
Using the preconditioned select... in statement, you must generate placeholders with the same number of queries.
$queryParams = [456089015, 456089016, 456089017, 456089018, 456089019, 456089020, 456089021, 456089022, 456089023, 456089024, 456089025, 678689287];$markers = str_repeat('?,', count($queryParams) - 1) . '?';$st = $dbh->prepare("SELECT * FROM user WHERE id IN (${markers}) ORDER BY id ASC");$st->execute($queryParams);$result = $st->fetchAll();
Pdo does not support binding such arrays.
Like the mistake I made before, the value range after "in", how many values are there, and how many question marks are there, but not a question mark.