Is this a pdo bug?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.