# Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active in /var/www/app/src/Repository/UserRepository.php:22

- **ID:** `php/pdo-prepared-statement-column-count`
- **Domain:** php
- **Category:** protocol_error
- **Error Code:** `HY000/2014`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

PDO's buffered query mode is exhausted when a previous query's result set has not been fully fetched or closed, and a new query is attempted on the same connection, which MySQL forbids.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| PHP 7.4 | active | — | — |
| PHP 8.0 | active | — | — |
| PHP 8.1 | active | — | — |
| PHP 8.2 | active | — | — |
| PHP 8.3 | active | — | — |
| MySQL 5.7 | active | — | — |
| MySQL 8.0 | active | — | — |
| MariaDB 10.5 | active | — | — |

## Workarounds

1. **Ensure all previous result sets are fetched or closed before executing a new query: $stmt = $pdo->query('SELECT * FROM users'); $rows = $stmt->fetchAll(); // fetch all rows to free the result; then execute next query.** (90% success)
   ```
   Ensure all previous result sets are fetched or closed before executing a new query: $stmt = $pdo->query('SELECT * FROM users'); $rows = $stmt->fetchAll(); // fetch all rows to free the result; then execute next query.
   ```
2. **Close the cursor explicitly with $stmt->closeCursor() after fetching if not using fetchAll(), especially for unbuffered queries.** (85% success)
   ```
   Close the cursor explicitly with $stmt->closeCursor() after fetching if not using fetchAll(), especially for unbuffered queries.
   ```
3. **Use separate PDO connections for concurrent queries: $pdo1 = new PDO(...); $pdo2 = new PDO(...); to avoid interference.** (80% success)
   ```
   Use separate PDO connections for concurrent queries: $pdo1 = new PDO(...); $pdo2 = new PDO(...); to avoid interference.
   ```

## Dead Ends

- **** — Setting PDO::MYSQL_ATTR_USE_BUFFERED_QUERY to false globally may cause memory issues and does not force fetching; it only switches to unbuffered mode which still requires closing. (70% fail)
- **** — Simply restarting the database server clears all connections temporarily, but the code will trigger the same error on the next request if not fixed. (90% fail)
