Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDOStatement fetch methods not properly handling PDO::FETCH_OBJ mode #11

Open
nick-potts opened this issue Jan 11, 2025 · 0 comments
Open

Comments

@nick-potts
Copy link

The current PDOStatement implementation has two issues with object fetching:

  • In the fetch() method, while there is a case for PDO::FETCH_OBJ that converts the row to an object using (object) $row, the method's return type is incorrectly typed as array instead of mixed.
  • In the fetchAll() method, the PDO::FETCH_OBJ case is incorrectly implemented. It's currently returning the raw $allRows array without converting each row to an object:
return match ($mode) {
  PDO::FETCH_BOTH => array_merge($allRows, $rowValues),
  PDO::FETCH_ASSOC, PDO::FETCH_NAMED => $allRows,
  PDO::FETCH_NUM => $rowValues,
  PDO::FETCH_OBJ => $allRows, // <-- This is wrong
  default => throw new \PDOException('Unsupported fetch mode.'),
};

Expected Behavior

  • The fetch() method should have a return type of mixed to properly reflect that it can return objects.
  • The fetchAll() method should convert each row to an object when PDO::FETCH_OBJ is specified.

Impact

This bug affects any Laravel applications using the libsql driver that expect to receive objects from database queries, which is the default behavior in Laravel. Currently, it requires workarounds like manually casting results to objects or using Laravel's collection methods to handle the conversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant