这个是pdo的bug吗?
<code>$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); </code>
其中只有678689287是存在的,结果返回为空;如果把678689287放在第一位,就有返回。
是不是个bug?
回复内容:
<code>$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); </code>
其中只有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后面的数值范围,有多少个数值,就来多少个问号,一个问号不行。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
