Description
MySqlConnection::query() and MySqlConnection::execute() pass $bindings directly to $statement->execute($bindings), which causes PDO to cast PHP arrays to the literal string "Array" — the same root cause as #71 but for the MySQL driver. JSON columns end up storing "Array" (or failing the JSON parse, depending on column type and SQL mode).
#71 was fixed in database-pgsql by intercepting arrays in PgSqlConnection::bindValues() and JSON-encoding them with JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE. MySQL needs the equivalent treatment.
Steps to Reproduce
- Define an entity with a JSON-typed column:
#[Column(type: 'json', nullable: true)]
public ?array $metadata = null;
- Assign an array value and save against MySQL:
$entity->metadata = ['key' => 'value'];
$repository->save($entity);
Expected Behavior
The array is JSON-encoded before binding, matching the database-pgsql behavior fixed in #71.
Actual Behavior
PHP Warning: Array to string conversion. The literal string "Array" is bound, causing either an invalid-JSON write or a silent storage of "Array" depending on column type.
Suggested fix
Mirror the database-pgsql approach: refactor MySqlConnection to use an explicit bindValues() helper that detects arrays and json_encode()s them with JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE, wrapping JsonException in a domain ConnectionException::invalidArrayBinding() factory for consistency with the pgsql driver.
Package
database-mysql
Source
Discovered while reviewing #71 / #72.
Description
MySqlConnection::query()andMySqlConnection::execute()pass$bindingsdirectly to$statement->execute($bindings), which causes PDO to cast PHP arrays to the literal string"Array"— the same root cause as #71 but for the MySQL driver. JSON columns end up storing"Array"(or failing the JSON parse, depending on column type and SQL mode).#71 was fixed in
database-pgsqlby intercepting arrays inPgSqlConnection::bindValues()and JSON-encoding them withJSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE. MySQL needs the equivalent treatment.Steps to Reproduce
Expected Behavior
The array is JSON-encoded before binding, matching the
database-pgsqlbehavior fixed in #71.Actual Behavior
PHP Warning: Array to string conversion. The literal string
"Array"is bound, causing either an invalid-JSON write or a silent storage of"Array"depending on column type.Suggested fix
Mirror the
database-pgsqlapproach: refactorMySqlConnectionto use an explicitbindValues()helper that detects arrays andjson_encode()s them withJSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE, wrappingJsonExceptionin a domainConnectionException::invalidArrayBinding()factory for consistency with the pgsql driver.Package
database-mysql
Source
Discovered while reviewing #71 / #72.