Exemple #1
0
 /**
  * Establishes a connection to the defined database.
  *
  * @return void
  */
 public function connect()
 {
     if ($this->connected === TRUE) {
         return;
     }
     if ($this->configuration['db']['driver'] != 'sqlite3') {
         $this->logger->error('Cannot connect to a non-sqlite3 database connection!');
         return;
     }
     $flag = $this->readonly ? SQLITE3_OPEN_READONLY : SQLITE3_OPEN_READWRITE;
     $this->sqlite3->open($this->db, $flag | SQLITE3_OPEN_CREATE, '');
     if ($this->sqlite3->lastErrorCode() === 0) {
         $this->connected = TRUE;
     }
 }
 /**
  * @param $db_filename = string fullpath to db-file
  * @param $access_mode = integer [ 0 = readonly | 1 = writeable | 2 = createIfNotExist ] default in parent is 3 (writeable + createIfNotExist)
  **/
 public function open($db_filename, $access_mode = 0, $encryptionKey = '')
 {
     $create = false;
     switch ($access_mode) {
         case 3:
         case 2:
             $mode = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE;
             $create = true;
             break;
         case 1:
             $mode = SQLITE3_OPEN_READWRITE;
             break;
         default:
             $mode = SQLITE3_OPEN_READONLY;
             break;
     }
     // first check for file
     if (!$create && !file_exists($db_filename) || !$create && $mode == 0 && !is_readable($db_filename) || !$create && $mode == 1 && (!is_writable($db_filename) || !is_readable($db_filename))) {
         return false;
     }
     // open file
     $this->fn = $db_filename;
     parent::open($db_filename, $mode, $encryptionKey);
     // check if file is a valid db
     $check = @parent::querySingle('SELECT count(*) FROM sqlite_master');
     $code = @parent::lastErrorCode();
     if (0 < $check || 0 == $check && 0 == $code) {
         return true;
     } else {
         $this->errormsg = parent::lastErrorMsg();
         return false;
     }
 }
Exemple #3
0
 /**
  * Non-persistent database connection
  *
  * @access	private called by the base class
  * @return	resource
  */
 function db_connect()
 {
     //if ( ! $conn_id = @sqlite_open(, FILE_WRITE_MODE, $error))
     if (!($conn_id = @SQLite3::open($this->database, $error))) {
         log_message('error', $error);
         if ($this->db_debug) {
             $this->display_error($error, '', TRUE);
         }
         return FALSE;
     }
     return $conn;
 }
Exemple #4
0
<?php

try {
    $db = new SQLite3(__DIR__ . '/db1.db');
    $db->open(__DIR__ . '/db1.db');
} catch (Exception $ex) {
    var_dump($ex->getMessage());
}
@unlink(__DIR__ . '/db1.db');
public  function __construct($filename='http_sessions.db'){
        $this->savePath = ini_get('session.save_path'). DIRECTORY_SEPARATOR .$filename;
        $this->dbHandle = parent::open($this->savePath);}