Skip to content

Array values bound as literal "Array" string instead of JSON (MySQL) #81

@markshust

Description

@markshust

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

  1. Define an entity with a JSON-typed column:
#[Column(type: 'json', nullable: true)]
public ?array $metadata = null;
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions