Bug Description
DataType::BOOL columns map to bit(1) in MySQL. The prepared statement binding in MySQLQuery::addBinding() and MySQLInsertBuilder::parseValues() passes the raw PHP boolean without casting to integer. MySQL's bit(1) rejects this with "Data too long for column".
Steps to Reproduce
Define a BOOL column:
#[Column(name: 'is_active', type: DataType::BOOL, default: true)]
Insert with a PHP boolean:
$db->table('users')->insert(['is-active' => true])->execute();
// Error: 1406 - Data too long for column 'is_active'
Root Cause
In MySQLQuery::addBinding() (line 44):
$this->bindings['values'][] = $value; // Raw PHP true/false
In MySQLInsertBuilder::parseValues() (line 36):
$queryParams['values'][$index][] = $val; // Raw PHP true/false
Both set bind type to 'i' (integer) but don't cast the value. When mysqli_stmt::bind_param() receives a PHP boolean with type 'i', it doesn't convert it to 1/0 properly for bit(1) columns.
Note: MySQLColumn::cleanValueHelper() correctly handles this for raw SQL by converting to b'1'/b'0', but the prepared statement path bypasses cleanValue().
Proposed Fix
Cast the value to (int) before adding to bindings in both locations:
MySQLQuery::addBinding():
if ($colType == 'int' || $colType == 'bit' || in_array($colType, Column::BOOL_TYPES)) {
$this->bindings['values'][] = (int) $value;
$this->bindings['bind'] .= 'i';
}
MySQLInsertBuilder::parseValues():
if ($colType == 'int' || $colType == 'bit' || in_array($colType, Column::BOOL_TYPES)) {
$queryParams['bind'] .= 'i';
$queryParams['values'][$index][] = (int) $val;
}
WebFiori Version
webfiori/database v2.0.3
PHP Version
8.4.18
Operating System
Linux
Bug Description
DataType::BOOLcolumns map tobit(1)in MySQL. The prepared statement binding inMySQLQuery::addBinding()andMySQLInsertBuilder::parseValues()passes the raw PHP boolean without casting to integer. MySQL'sbit(1)rejects this with "Data too long for column".Steps to Reproduce
Define a BOOL column:
Insert with a PHP boolean:
Root Cause
In
MySQLQuery::addBinding()(line 44):In
MySQLInsertBuilder::parseValues()(line 36):Both set bind type to
'i'(integer) but don't cast the value. Whenmysqli_stmt::bind_param()receives a PHP boolean with type'i', it doesn't convert it to1/0properly forbit(1)columns.Note:
MySQLColumn::cleanValueHelper()correctly handles this for raw SQL by converting tob'1'/b'0', but the prepared statement path bypassescleanValue().Proposed Fix
Cast the value to
(int)before adding to bindings in both locations:MySQLQuery::addBinding():MySQLInsertBuilder::parseValues():WebFiori Version
webfiori/database v2.0.3
PHP Version
8.4.18
Operating System
Linux