php / php/doc-en

PDO MySQL returns php value type "string" for column type "YEAR"

Open
#1,631 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: pdo
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

Description

The following code:

<?php
/**
 * Given:
 * CREATE TABLE `t` (
 *   `y` year(4) DEFAULT NULL,
 *   `m` tinyint(3) DEFAULT NULL
 * ) ENGINE=InnoDB DEFAULT CHARSET=utf8
 * INSERT INTO t VALUES (2001, 11);
 */
$pdo = new PDO($dsn, null, null, [ PDO::ATTR_EMULATE_PREPARES => false ]);
var_dump($pdo->query("SELECT * FROM t")->fetchAll(PDO::FETCH_ASSOC));

Resulted in this output:

array(1) {
  [0]=>
  array(2) {
    ["y"]=>
    string(4) "2001"
    ["m"]=>
    int(11)
  }
}

But I expected this output instead:

array(1) {
  [0]=>
  array(2) {
    ["y"]=>
    int(2001)
    ["m"]=>
    int(11)
  }
}

This breaking change occurs between PHP v8.0 & v8.1.

PHP Version

8.1.6

Operating System

Alpine 10.2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PDO MySQL reproducer in the issue and compare its result on PHP 8.0 and 8.1, focusing on the YEAR column returned by FETCH_ASSOC. Determine whether the observed type change is expected and identify the relevant PHP documentation entry; done means the behavior and any required documentation change are confirmed.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.