Connection::getDriver PHP Method

getDriver() public method

Gets the name of the correct database driver to use. As a side effect, sets the platform.
public getDriver ( (return-by-ref) &$description ) : -3
$description (return-by-ref)
return -3 class name of the driver eg. Postgres84
    function getDriver(&$description)
    {
        $v = pg_version($this->conn->_connectionID);
        if (isset($v['server'])) {
            $version = $v['server'];
        }
        // If we didn't manage to get the version without a query, query...
        if (!isset($version)) {
            $adodb = new ADODB_base($this->conn);
            $sql = "SELECT VERSION() AS version";
            $field = $adodb->selectField($sql, 'version');
            // Check the platform, if it's mingw, set it
            if (preg_match('/ mingw /i', $field)) {
                $this->platform = 'MINGW';
            }
            $params = explode(' ', $field);
            if (!isset($params[1])) {
                return -3;
            }
            $version = $params[1];
            // eg. 8.4.4
        }
        $description = "PostgreSQL {$version}";
        // Detect version and choose appropriate database driver
        switch (substr($version, 0, 3)) {
            case '9.5':
                return 'Postgres';
                break;
            case '9.4':
                return 'Postgres94';
                break;
            case '9.3':
                return 'Postgres93';
                break;
            case '9.2':
                return 'Postgres92';
                break;
            case '9.1':
                return 'Postgres91';
                break;
            case '9.0':
                return 'Postgres90';
                break;
            case '8.4':
                return 'Postgres84';
                break;
            case '8.3':
                return 'Postgres83';
                break;
            case '8.2':
                return 'Postgres82';
                break;
            case '8.1':
                return 'Postgres81';
                break;
            case '8.0':
            case '7.5':
                return 'Postgres80';
                break;
            case '7.4':
                return 'Postgres74';
                break;
        }
        /* All <7.4 versions are not supported */
        // if major version is 7 or less and wasn't cought in the
        // switch/case block, we have an unsupported version.
        if ((int) substr($version, 0, 1) < 8) {
            return null;
        }
        // If unknown version, then default to latest driver
        return 'Postgres';
    }

Usage Example

Example #1
0
 /**
  * @return null
  */
 public function setUp()
 {
     $this->runDbStartupTask();
     $connector = DbRegistry::getConnector('af-tester');
     $this->conn = $connector->getConnection();
     $this->conn->connect();
     $driver = $this->conn->getDriver();
     $this->stmtDriver = $driver->stmt_init();
     $this->stmt = new PreparedStmt($this->stmtDriver);
 }
All Usage Examples Of Connection::getDriver