PDO execute not correctly binding booleans
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C
- Sterne
- 40.4k
- Forks
- 8.1k
- Ø Merge
- 2 T. 13 Std.
- Gemergte PRs (30 T.)
- 96
Beschreibung
Description
The following code:
<?php
$db = new PDO(...);
$sql = <<<SQL
CREATE TABLE test (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`birthday` DATE NOT NULL,
`name` VARCHAR(40) NOT NULL,
`salary` INT NOT NULL,
`boss` BIT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
SQL;
$query = $db->prepare($sql);
$query->execute();
$sql = <<<SQL
INSERT INTO test
(birthday, name, salary, boss)
VALUES (:birthday, :name, :salary, :boss)
SQL;
$query = $db->prepare($sql);
$staff = [
[
'birthday' => (new DateTime('1995-05-01'))->format('Y-m-d'),
'name' => 'Sharon',
'salary' => '200',
'boss' => TRUE,
],
];
foreach ($staff as $member) {
/* works
$query->bindValue('birthday', $member['birthday'], PDO::PARAM_STR);
$query->bindValue('name', $member['name'], PDO::PARAM_STR);
$query->bindValue('salary', $member['salary'], PDO::PARAM_INT);
$query->bindValue('boss', $member['boss'], PDO::PARAM_BOOL);
$query->execute();
*/
// does not work
$query->execute($member);
}
Resulted in this output:
SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'boss' at row 1
But I expected execute() not to throw an error.
I clearly see the problem in the source as the parameter is always set to be a string on line 424:
Can't the execute() code be improved to check for the param type like it is done in bindValue()?
PHP Version
8.2.0 RC3
Operating System
Alpine Linux
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das PDO-Beispiel mit der gemeldeten PHP-Version, lies anschließend ext/pdo/pdo_stmt.c im Bereich der Zeilen 411–425 und vergleiche es mit bindValue() im Bereich der Zeilen 1465–1475. Bestätige, wie execute() boolesche Werte behandelt, und füge eine Regressionstestabdeckung hinzu, die das erwartete BIT-Bindungsverhalten zeigt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c, php
- Bereich
- databases
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100