Saving booleans fails in one environment with the message - General error: 1366 Incorrect integer value: ''

Viewed 24

The following works on my local environment:

$connection->update('requests', ['is_escalated' => false], ['id' => $serviceLineEntry->request_id]);

However, in my sandbox environment it fails with the following message:

[PDOException] SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'is_escalated'

Local environment:

MariaDB (10.4.21-MariaDB)
PHP 7.4.25 (cli) (built: Oct 20 2021 09:30:08) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Sandbox:

Azure Database for MySQL (5.7)
PHP 7.4.28 (cli) (built: Mar 24 2022 19:12:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies

Is this due to the databases being different?

Update 1

Here's the column definition:

CREATE TABLE `requests` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    ...
  `is_escalated` tinyint(1) unsigned NOT NULL DEFAULT 0,
    ...
  PRIMARY KEY (`id`),
) ENGINE=InnoDB AUTO_INCREMENT=58249 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
1 Answers

As your field is an integer, you can not pass boolean values.

['is_escalated' => 0] // false
['is_escalated' => 1] // true

You can cast a boolean to int

['is_escalated' => (int)true]  // 1
['is_escalated' => (int)false] // 0
Related