mrcrypster/mysqly

Insert into column type BIT(1) gives truncate-error

Closed this issue · 1 comments

When trying to insert a value (0,1,true,false,'0','1') into a column with type BIT(1), I get an error:

Fatal error: Uncaught PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'active' at row 1 in mysqly.php:99
Stack trace:
#0 mysqly.php(99): PDOStatement->execute(Array)
#1 mysqly.php(324): mysqly::exec('INSERT INTO `TABLE...', Array)
#2 page.php(68): mysqly::multi_insert('TABLE', Array)

Workaround: I changed the columntype to TINYINT(1).

Error also appearce when using single row insert

Fixed according to this https://stackoverflow.com/questions/24326283/php-pdo-bindparam-and-mysql-bit

Commit: 9269218

Long story short, PDOStatement::execute treats all params in arguments as string params.
At the same time it has bindValue() method that allows setting value type explicitly.
Bit column in Mysql is mapped to boolean param value in PDO.