Skip to content

SQLSRV unsupported PDO attribute #1140

@ikennykachun

Description

@ikennykachun

Information

  • Version of Medoo: 2.2
  • Version of PHP: 8.2.10 / 8.2.28
  • Type of Database: MSSQL
  • System: Linux (Ubuntu / RedHat)

Describe the Problem
Medoo->info() provides database connection information, however, SQLSRV not support connection status attribute (PDO::ATTR_CONNECTION_STATUS) which gives error "SQLSTATE[IMSSP]: An invalid attribute was designated on the PDO object."

Code Snippet
Suggested Update

public function info(): array
    {
        // Move "PDO::ATTR_" up for support MSSQL special prefix
        $output = [
            'server' => 'PDO::ATTR_SERVER_INFO',
            'driver' => 'PDO::ATTR_DRIVER_NAME',
            'client' => 'PDO::ATTR_CLIENT_VERSION',
            'version' => 'PDO::ATTR_SERVER_VERSION',
            'connection' => 'PDO::ATTR_CONNECTION_STATUS'
        ];

        if ($this->type == 'mssql'){
         unset($output['connection']);
         // Put MSSQL supported attribute of interest [if have]
          $output['timeout']='PDO::SQLSRV_ATTR_QUERY_TIMEOUT';
        }

        foreach ($output as $key => $value) {
            try {
                $output[$key] = $this->pdo->getAttribute(constant('' . $value));
            } catch (PDOException $e) {
                $output[$key] = $e->getMessage();
            }
        }

        $output['dsn'] = $this->dsn;

        return $output;
    }

Expected Behavior
A clear and concise description of what you expected to happen.

Actual Behavior
A clear and concise description of what actually happened.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions