Exemplo n.º 1
0
 /**
  * @see Connection::connect()
  */
 public function connect($dsninfo, $flags = 0)
 {
     if (!function_exists('odbc_connect')) {
         throw new SQLException('odbc extension not loaded');
     }
     $adapterclass = isset($dsninfo['adapter']) ? $dsninfo['adapter'] : null;
     if (!$adapterclass) {
         $adapterclass = 'ODBCAdapter';
     } else {
         $adapterclass .= 'Adapter';
     }
     Creole::import('creole.drivers.odbc.adapters.' . $adapterclass);
     $this->adapter = new $adapterclass();
     $this->dsn = $dsninfo;
     $this->flags = $flags;
     if (!($this->flags & Creole::COMPAT_ASSOC_LOWER) && !$this->adapter->preservesColumnCase()) {
         trigger_error('Connection created without Creole::COMPAT_ASSOC_LOWER, ' . 'but driver does not support case preservation.', E_USER_WARNING);
         $this->flags != Creole::COMPAT_ASSOC_LOWER;
     }
     $persistent = ($flags & Creole::PERSISTENT) === Creole::PERSISTENT;
     if ($dsninfo['database']) {
         $odbcdsn = $dsninfo['database'];
     } elseif ($dsninfo['hostspec']) {
         $odbcdsn = $dsninfo['hostspec'];
     } else {
         $odbcdsn = 'localhost';
     }
     $user = @$dsninfo['username'];
     $pw = @$dsninfo['password'];
     $connect_function = $persistent ? 'odbc_pconnect' : 'odbc_connect';
     $conn = @$connect_function($odbcdsn, $user, $pw, SQL_CUR_USE_IF_NEEDED);
     if (!is_resource($conn)) {
         throw new SQLException('connect failed', $this->nativeError(), $odbcdsn);
     }
     $this->dblink = $conn;
     /**
      * This prevents blob fields from being fetched when a row is loaded
      * from a recordset. Clob fields however are loaded with up to
      * 'odbc.defaultlrl' data. This should be the default anyway, but we'll
      * set it here just to keep things consistent.
      */
     @odbc_binmode(0, ODBC_BINMODE_PASSTHRU);
     @odbc_longreadlen(0, ini_get('odbc.defaultlrl'));
 }