Skip to content

PDO: No exception when wrong data is bound to statement #13167

Closed
@butesa

Description

@butesa

Description

The following code:

<?php

declare(strict_types=1);

$pdo = new PDO('mysql:host=localhost;dbname=demo;charset=utf8mb4', 'user', 'pass');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

$pdo->exec('DROP TABLE IF EXISTS test');
$pdo->exec('CREATE TABLE test (mode TINYINT)');

$statement = $pdo->prepare('INSERT INTO test (mode) VALUES (?)');
$statement->bindValue(1, new DateTime(), PDO::PARAM_INT);

$success = $statement->execute();
$error = $pdo->errorInfo();

var_dump($success);
var_dump($error);

Resulted in this output:

bool(false)
array(3) {
  [0]=>
  string(5) "00000"
  [1]=>
  NULL
  [2]=>
  NULL
}

But I expected this output instead:
An unsuccessful PDO command should throw an exception.

PHP Version

PHP 8.1.2

Operating System

Ubuntu 22.04.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions