Skip to content

Conversation

mesour
Copy link

@mesour mesour commented Aug 22, 2025

  • Add sslcert and sslrootcert to PgSQL\Connection and fix a small bug
  • BC break?no

Changes Made:

  1. Added SSL Certificate Support for PostgreSQL:

    • Extended the list of supported configuration parameters to include and sslcert, sslrootcert
    • These parameters allow specifying SSL certificates for secure connections to PostgreSQL databases
  2. Fixed TypeError Bug in Connection Handling:

    • Problem: The original code directly assigned values to $this->connection property, which has a strict type PgSql\Connection declaration
    • Issue: When pg_connect() returned false (connection failure), it caused a TypeError because false cannot be assigned to a property typed as PgSql\Connection
    • Consequence: The TypeError was thrown before reaching the proper error handling code below, making it impossible to determine what connection error actually occurred
    • Solution: Introduced a local variable that: $connection
      • First collects the connection result (whether from $config['resource'] or pg_pconnect())
      • Then validates the connection type with proper error checking
      • Only assigns to $this->connection after successful validation
      • This ensures that connection failures are properly caught and reported with meaningful error messages instead of generic TypeErrors

Technical Impact:

  • Before: Connection failures resulted in unhelpful TypeErrors, masking the actual database connection issues
  • After: Connection failures now properly throw with descriptive error messages, making debugging much easier Dibi\DriverException
  • Bonus: Added support for SSL certificate configuration in PostgreSQL connections

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

Successfully merging this pull request may close these issues.

1 participant