這個是pdo的bug嗎?

來源:互聯網
上載者:User
$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);

其中只有678689287是存在的,結果返回為空白;如果把678689287放在第一位,就有返回。

是不是個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);

其中只有678689287是存在的,結果返回為空白;如果把678689287放在第一位,就有返回。

是不是個bug?

用預先處理的的select...in語句,你得產生與查詢數量相同的預留位置

$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不支援這種數組綁定

和我以前犯的錯誤一樣,in後面的數值範圍,有多少個數值,就來多少個問號,一個問號不行。

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.