PDO execute not correctly binding booleans
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Riproduci l'esempio PDO con la versione di PHP indicata, quindi leggi ext/pdo/pdo_stmt.c intorno alle righe 411-425 e confrontalo con bindValue() intorno alle righe 1465-1475. Conferma come execute() gestisce i valori booleani e aggiungi una copertura di regressione che mostri il comportamento previsto del binding di BIT.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- C
- Stelle
- 40.4k
- Fork
- 8.2k
- Merge medio
- 2g 15h
- PR unite (30g)
- 103
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di php/php-src
-
Bug SAPI: cli_server Status: Verified
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Bug Status: Needs Triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Flaky hrtime.phpt test ApertaBug Category: Tests Status: Verified
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Issue simili
-
[adam] AdamNet network read doesn't cap to MAX_ADAM_PACKET_LEN, overflows client receive buffers Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
FujiNetWIFI/fujinet-firmware#1649 · 2 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
HarbourMasters/Shipwright#7229 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
riscv-software-src/riscv-isa-sim#2435 · 1 commento ·
-
bug Self Built Image SNAPSHOT Supported Device target/ramips
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100