| 367 | | if (!empty($this->database_name)) { |
|---|
| 368 | | if ($database_file !== ':memory:') { |
|---|
| | 367 | if (empty($this->database_name)) { |
|---|
| | 368 | return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, |
|---|
| | 369 | 'unable to establish a connection', __FUNCTION__); |
|---|
| | 370 | } |
|---|
| | 371 | |
|---|
| | 372 | if ($database_file !== ':memory:') { |
|---|
| | 373 | if (!file_exists($database_file)) { |
|---|
| | 374 | if (!touch($database_file)) { |
|---|
| | 375 | return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
|---|
| | 376 | 'Could not create database file', __FUNCTION__); |
|---|
| | 377 | } |
|---|
| | 378 | if (!isset($this->dsn['mode']) |
|---|
| | 379 | || !is_numeric($this->dsn['mode']) |
|---|
| | 380 | ) { |
|---|
| | 381 | $mode = 0644; |
|---|
| | 382 | } else { |
|---|
| | 383 | $mode = octdec($this->dsn['mode']); |
|---|
| | 384 | } |
|---|
| | 385 | if (!chmod($database_file, $mode)) { |
|---|
| | 386 | return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
|---|
| | 387 | 'Could not be chmodded database file', __FUNCTION__); |
|---|
| | 388 | } |
|---|
| 370 | | if (!touch($database_file)) { |
|---|
| 371 | | return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
|---|
| 372 | | 'Could not create database file', __FUNCTION__); |
|---|
| 373 | | } |
|---|
| 374 | | if (!isset($this->dsn['mode']) |
|---|
| 375 | | || !is_numeric($this->dsn['mode']) |
|---|
| 376 | | ) { |
|---|
| 377 | | $mode = 0644; |
|---|
| 378 | | } else { |
|---|
| 379 | | $mode = octdec($this->dsn['mode']); |
|---|
| 380 | | } |
|---|
| 381 | | if (!chmod($database_file, $mode)) { |
|---|
| 382 | | return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
|---|
| 383 | | 'Could not be chmodded database file', __FUNCTION__); |
|---|
| 384 | | } |
|---|
| 385 | | if (!file_exists($database_file)) { |
|---|
| 386 | | return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
|---|
| 387 | | 'Could not be found database file', __FUNCTION__); |
|---|
| 388 | | } |
|---|
| | 390 | return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
|---|
| | 391 | 'Could not be found database file', __FUNCTION__); |
|---|
| 390 | | if (!is_file($database_file)) { |
|---|
| 391 | | return $this->raiseError(MDB2_ERROR_INVALID, null, null, |
|---|
| 392 | | 'Database is a directory name', __FUNCTION__); |
|---|
| 393 | | } |
|---|
| 394 | | if (!is_readable($database_file)) { |
|---|
| 395 | | return $this->raiseError(MDB2_ERROR_ACCESS_VIOLATION, null, null, |
|---|
| 396 | | 'Could not read database file', __FUNCTION__); |
|---|
| 397 | | } |
|---|
| 398 | | } |
|---|
| 399 | | |
|---|
| 400 | | $connect_function = ($this->options['persistent'] ? 'sqlite_popen' : 'sqlite_open'); |
|---|
| 401 | | $php_errormsg = ''; |
|---|
| 402 | | if (version_compare('5.1.0', PHP_VERSION, '>')) { |
|---|
| 403 | | @ini_set('track_errors', true); |
|---|
| 404 | | $connection = @$connect_function($database_file); |
|---|
| 405 | | @ini_restore('track_errors'); |
|---|
| 406 | | } else { |
|---|
| 407 | | $connection = @$connect_function($database_file, 0666, $php_errormsg); |
|---|
| 408 | | } |
|---|
| 409 | | $this->_lasterror = $php_errormsg; |
|---|
| 410 | | if (!$connection) { |
|---|
| 411 | | return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, |
|---|
| 412 | | 'unable to establish a connection', __FUNCTION__); |
|---|
| 413 | | } |
|---|
| 414 | | |
|---|
| 415 | | $this->connection = $connection; |
|---|
| 416 | | $this->connected_dsn = $this->dsn; |
|---|
| 417 | | $this->connected_database_name = $database_file; |
|---|
| 418 | | $this->opened_persistent = $this->getoption('persistent'); |
|---|
| 419 | | $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype; |
|---|
| 420 | | } |
|---|
| | 393 | } |
|---|
| | 394 | if (!is_file($database_file)) { |
|---|
| | 395 | return $this->raiseError(MDB2_ERROR_INVALID, null, null, |
|---|
| | 396 | 'Database is a directory name', __FUNCTION__); |
|---|
| | 397 | } |
|---|
| | 398 | if (!is_readable($database_file)) { |
|---|
| | 399 | return $this->raiseError(MDB2_ERROR_ACCESS_VIOLATION, null, null, |
|---|
| | 400 | 'Could not read database file', __FUNCTION__); |
|---|
| | 401 | } |
|---|
| | 402 | } |
|---|
| | 403 | |
|---|
| | 404 | $connect_function = ($this->options['persistent'] ? 'sqlite_popen' : 'sqlite_open'); |
|---|
| | 405 | $php_errormsg = ''; |
|---|
| | 406 | if (version_compare('5.1.0', PHP_VERSION, '>')) { |
|---|
| | 407 | @ini_set('track_errors', true); |
|---|
| | 408 | $connection = @$connect_function($database_file); |
|---|
| | 409 | @ini_restore('track_errors'); |
|---|
| | 410 | } else { |
|---|
| | 411 | $connection = @$connect_function($database_file, 0666, $php_errormsg); |
|---|
| | 412 | } |
|---|
| | 413 | $this->_lasterror = $php_errormsg; |
|---|
| | 414 | if (!$connection) { |
|---|
| | 415 | return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, |
|---|
| | 416 | 'unable to establish a connection', __FUNCTION__); |
|---|
| | 417 | } |
|---|
| | 418 | |
|---|
| | 419 | if ($this->fix_assoc_fields_names || |
|---|
| | 420 | $this->options['portability'] & MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES) |
|---|
| | 421 | { |
|---|
| | 422 | @sqlite_query("PRAGMA short_column_names = 1", $connection); |
|---|
| | 423 | $this->fix_assoc_fields_names = true; |
|---|
| | 424 | } |
|---|
| | 425 | |
|---|
| | 426 | $this->connection = $connection; |
|---|
| | 427 | $this->connected_dsn = $this->dsn; |
|---|
| | 428 | $this->connected_database_name = $database_file; |
|---|
| | 429 | $this->opened_persistent = $this->getoption('persistent'); |
|---|
| | 430 | $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype; |
|---|
| | 431 | |
|---|