protected static function db() { if (self::$db === false) { self::$db = sqlite_open("app/temp/datadb.sqlite"); } return self::$db; }
/** * @param $file * @throws AdapterException */ public function __construct($file) { $this->_dbHandle = sqlite_open($file, 0666, $error); if (!$this->_dbHandle) { throw new AdapterException($error); } }
function __construct($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect) { // Prepend $db_name with the path to the forum root directory $db_name = LUNA_ROOT . $db_name; $this->prefix = $db_prefix; if (!file_exists($db_name)) { @touch($db_name); @chmod($db_name, 0666); if (!file_exists($db_name)) { error('Unable to create new database \'' . $db_name . '\'. Permission denied', __FILE__, __LINE__); } } if (!is_readable($db_name)) { error('Unable to open database \'' . $db_name . '\' for reading. Permission denied', __FILE__, __LINE__); } if (!forum_is_writable($db_name)) { error('Unable to open database \'' . $db_name . '\' for writing. Permission denied', __FILE__, __LINE__); } if ($p_connect) { $this->link_id = @sqlite_popen($db_name, 0666, $sqlite_error); } else { $this->link_id = @sqlite_open($db_name, 0666, $sqlite_error); } if (!$this->link_id) { error('Unable to open database \'' . $db_name . '\'. SQLite reported: ' . $sqlite_error, __FILE__, __LINE__); } else { return $this->link_id; } }
function SQL($connString, $user = "", $pass = "") { list($this->adapter, $options) = explode(":", $connString, 2); if ($this->adapter != "sqlite") { $this->adapter = "mysql"; } $optionsList = explode(";", $options); foreach ($optionsList as $option) { list($a, $b) = explode("=", $option); $opt[$a] = $b; } $this->options = $opt; $database = array_key_exists("database", $opt) ? $opt['database'] : ""; if ($this->adapter == "sqlite") { $this->method = "sqlite"; $this->conn = sqlite_open($database, 0666, $sqliteError); } else { $this->method = "mysql"; $host = array_key_exists("host", $opt) ? $opt['host'] : ""; $this->conn = @mysql_connect($host, $user, $pass); } if ($this->conn && $this->adapter == "mysql") { $this->query("SET NAMES 'utf8'"); } }
function Connect() { $database_file = $this->GetDatabaseFile($this->database_name); if ($this->connection != 0) { if (!strcmp($this->connected_database_file, $database_file)) { return 1; } sqlite_close($this->connection); $this->connection = 0; $this->affected_rows = -1; } if (!function_exists('sqlite_open')) { return $this->SetError("Connect", "SQLite support is not available in this PHP configuration"); } if (!@file_exists($database_file)) { return $this->SetError("Connect", "database does not exist"); } if (($this->connection = @sqlite_open($database_file)) == 0) { return $this->SetError("Connect", isset($php_errormsg) ? $php_errormsg : "Could not open SQLite database"); } if (isset($this->supported["Transactions"]) && !$this->auto_commit) { $this->Debug("Query: BEGIN TRANSACTION {$this->base_transaction_name}"); if (!@sqlite_exec("BEGIN TRANSACTION {$this->base_transaction_name};", $this->connection)) { sqlite_close($this->connection); $this->connection = 0; $this->affected_rows = -1; return $this->SetError("Connect", isset($php_errormsg) ? $php_errormsg : "Could not start transaction"); } $this->RegisterTransactionShutdown(0); } $this->connected_database_file = $database_file; return 1; }
function CreateDatabase(&$db, $name) { if (!function_exists("sqlite_open")) { return $db->SetError("Connect", "SQLite support is not available in this PHP configuration"); } $database_file = $db->GetDatabaseFile($name); if (@file_exists($database_file)) { return $db->SetError("Create database", "database already exists"); } @touch($database_file); if (!@file_exists($database_file)) { return $db->SetError("Create database", "Unable to create new database. Permission denied"); } $mode = isset($db->options["AccessMode"]) ? strcmp($db->options["AccessMode"][0], "0") ? intval($db->options["AccessMode"]) : octdec($db->options["AccessMode"]) : 0640; @chmod($database_file, $mode); if (!is_readable($database_file)) { @unlink($database_file); return $db->SetError("Create database", "Unable to open database for Reading. Permission denied"); } if (!is_writable($database_file)) { @unlink($database_file); return $db->SetError("Create database", "Unable to open database for Writing. Permission denied"); } $handle = @sqlite_open($database_file, $mode); if (!$handle) { @unlink($database_file); return $db->SetError("Create database", isset($php_errormsg) ? $php_errormsg : "could not create the database file"); } sqlite_close($handle); return 1; }
public function prepareDB($bWithData = true) { if (file_exists(dirname(__FILE__) . '/unittest.db')) { unlink(dirname(__FILE__) . '/unittest.db'); } $db = sqlite_open(dirname(__FILE__) . '/unittest.db'); $res = sqlite_query($db, 'CREATE TABLE people (id INTEGER PRIMARY KEY, firstName TEXT, lastName TEXT)', $sError); if ($res === false) { throw new Exception($sError); } if ($bWithData) { $res = sqlite_query($db, 'INSERT INTO people (id,firstName,lastName) VALUES (1, \'Jerome\', \'Piochet\')', $sError); if ($res === false) { throw new Exception($sError); } $res = sqlite_query($db, 'INSERT INTO people (id,firstName,lastName) VALUES (2, \'Tadao\', \'Poichet\')', $sError); if ($res === false) { throw new Exception($sError); } $res = sqlite_query($db, 'INSERT INTO people (id,firstName,lastName) VALUES (3, \'A\', \'B\')', $sError); if ($res === false) { throw new Exception($sError); } $res = sqlite_query($db, 'INSERT INTO people (id,firstName,lastName) VALUES (4, \'C\', \'D\')', $sError); if ($res === false) { throw new Exception($sError); } } sqlite_close($db); }
function open() { $this->db = sqlite_open($this->url, 0666, $sqliteerror); if (!$this->db) { die('接続失敗' . $sqliteerror); } }
/** * {@inheritDoc} */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . ($port ? ':' . $port : ''); $this->dbname = $database; $error = ''; if ($this->persistency) { if (!function_exists('sqlite_popen')) { $this->connect_error = 'sqlite_popen function does not exist, is sqlite extension installed?'; return $this->sql_error(''); } $this->db_connect_id = @sqlite_popen($this->server, 0666, $error); } else { if (!function_exists('sqlite_open')) { $this->connect_error = 'sqlite_open function does not exist, is sqlite extension installed?'; return $this->sql_error(''); } $this->db_connect_id = @sqlite_open($this->server, 0666, $error); } if ($this->db_connect_id) { @sqlite_query('PRAGMA short_column_names = 1', $this->db_connect_id); // @sqlite_query('PRAGMA encoding = "UTF-8"', $this->db_connect_id); } return $this->db_connect_id ? true : array('message' => $error); }
/** * Abra a conexão com o banco de dados SQLite * * <code> * $sqliteHandle = dbOpen_SQLite("sqlite", "database", "user", "password"); * </code> * * @param string $dbHost string de conexão com o banco de dados * @param string $dbDatabase[optional] string database utilizado * @param string $dbUser[optional] nome do usuário * @param string $dbPassword[optional] senha do usuário * * @return array com o handleId e o nome do driver * * @since Versão 1.0 */ function dbOpen_SQLite(&$dbHandle) { $debugBackTrace = debug_backtrace(); $debugFile = basename($debugBackTrace[1]["file"]); $debugFunction = $debugBackTrace[1]["function"]; $dbDriver = $dbHandle[dbHandleDriver]; if (!function_exists("sqlite_open")) { echo "<span style=\"text-align: left;\"><pre><b>{$dbDriver} - {$debugFile} - {$debugFunction}() - Open</b>:" . "<br />extension=<b>php_sqlite.dll</b> is not loaded"; echo "<hr />" . debugBackTrace(); echo "</pre></span>"; die; } $dbFilename = $dbHandle[dbHandleFilename]; $dbMode = $dbHandle[dbHandleMode]; if (substr($dbFilename, 0, 1)) { $dbFilename = substr($dbFilename, 1, strlen($dbFilename)); } $dbFilename = SiteRootDir . $dbFilename; // @TODO Incluir tratamento para ver se o driver está carregado if (!($SQLiteConn = @sqlite_open($dbFilename, $dbMode, $dbError))) { echo "<span style=\"text-align: left;\"><pre><b>{$dbDriver} - {$debugFile} - {$debugFunction}() - Connect</b>:" . "<br /><b>Filename</b>: {$dbFilename}" . "<br /><b>Mode</b>: {$dbMode}" . "<br /><b>Message</b>: [{$dbError}]"; echo "<hr />" . debugBackTrace(); echo "</pre></span>"; die; } return $SQLiteConn; }
/** * Initializes and opens the database * * Needs to be called right after loading this helper plugin */ function init($dbname, $updatedir) { global $conf; // check for already open DB if ($this->db) { if ($this->dbname == $dbname) { // db already open return true; } // close other db sqlite_close($this->db); $this->db = null; $this->dbname = ''; } $this->dbname = $dbname; $dbfile = $conf['metadir'] . '/' . $dbname . '.sqlite'; $init = !@file_exists($dbfile) || (int) @filesize($dbfile) < 3; $error = ''; $this->db = sqlite_open($dbfile, 0666, $error); if (!$this->db) { msg("SQLite: failed to open SQLite " . $this->dbname . " database ({$error})", -1); return false; } // register our custom aggregate function sqlite_create_aggregate($this->db, 'group_concat', array($this, '_sqlite_group_concat_step'), array($this, '_sqlite_group_concat_finalize'), 2); $this->_updatedb($init, $updatedir); return true; }
function db($dbpath, $dbname) { $this->dbh = @sqlite_open($dbpath . $dbname); if (!$this->dbh) { $this->print_error("Error", "<ol><b>Error establishing a database!</b><li>Are you sure you have the correct path?<li>Are you sure that you have typed the correct database instance name?<li>Are you sure that the database is installed?</ol>"); } }
function dblayer($db_host, $db_user, $db_pass, $db_name, $p_connect = false) { // Support SQLite if (!function_exists('sqlite_open')) { exit('This PHP environment doesn\'t have SQLite support built in. SQLite support is required if you want to use a SQLite database to run this forum. Consult the PHP documentation for further assistance.'); } // Prepend $db_name with the path to the forum root directory $db_name = EPS_ROOT . $db_name; if (!file_exists($db_name)) { @touch($db_name); @chmod($db_name, 0666); if (!file_exists($db_name)) { error('Unable to create new database \'' . $db_name . '\'. Permission denied', __FILE__, __LINE__); } } if (!is_readable($db_name)) { error('Unable to open database \'' . $db_name . '\' for reading. Permission denied', __FILE__, __LINE__); } if (!is_writable($db_name)) { error('Unable to open database \'' . $db_name . '\' for writing. Permission denied', __FILE__, __LINE__); } if ($p_connect) { $this->link_id = @sqlite_popen($db_name, 0666, $sqlite_error); } else { $this->link_id = @sqlite_open($db_name, 0666, $sqlite_error); } if (!$this->link_id) { error('Unable to open database \'' . $db_name . '\'. SQLite reported: ' . $sqlite_error, __FILE__, __LINE__); } else { return $this->link_id; } }
function SQLiteDatabase($dbfile) { $this->dbfile = $dbfile; //if db file doesn't exist, fill with skeleton if (file_exists($this->dbfile)) { $this->dbres = sqlite_open($this->dbfile, 0666, $sqliteerror); } else { //fill with skeleton $folder = dirname($this->dbfile); if (!is_writable($folder)) { //we need write permission to create database die("<p style=\"color:red;\">cannot create dabase. check permissions.</p>\n"); } else { $this->dbres = sqlite_open($this->dbfile, 0666, $sqliteerror); //photo table $sql = "create table photo (id INTEGER PRIMARY KEY, caption TEXT, "; $sql .= "counter INTEGER, number INTEGER, album TEXT, name TEXT)"; $this->query($sql); //comment table $sql = "create table comment (id INTEGER PRIMARY KEY, user TEXT, "; $sql .= "comment_body TEXT, photo_id INT, date DATETIME)"; $this->query($sql); } } }
protected function _connectDbOperation($db_params) { if (file_exists($db_params['name'])) return sqlite_open($db_params['name']); else return false; }
public function connect() { if ($this->_connection) { return; } // Extract the connection parameters, adding required variabels extract($this->_config['connection'] + array('database' => '', 'persistent' => FALSE)); try { if ($persistent) { // Create a persistent connection $this->_connection = sqlite_popen($database); } else { // Create a connection and force it to be a new link $this->_connection = sqlite_open($database); } } catch (Exception $e) { // No connection exists $this->_connection = NULL; throw new Database_Exception(':error', array(':error' => $e->getMessage()), $e->getCode()); } $this->_connection_id = sha1($dsn); if (!empty($this->_config['connection']['variables'])) { // Set session variables $variables = array(); foreach ($this->_config['connection']['variables'] as $var => $val) { $variables[] = 'SESSION ' . $var . ' = ' . $this->quote($val); } sqlite_query('SET ' . implode(', ', $variables), $this->_connection); } }
function sql_db($sqlserver, $trash, $trash, $trash, $persistency = true) { $this->persistency = $persistency; $this->server = $sqlserver; $this->db_connect_id = $this->persistency ? @sqlite_popen($this->server, 0666, $sqliteerror) : @sqlite_open($this->server, 0666, $sqliteerror); return $this->db_connect_id ? $this->db_connect_id : false; }
public function __construct() { if (!defined("WebOrbServicesPath")) { $dom = new DomDocument(); $dom->load(WebOrb . "weborb-config.xml"); $servicePath = $dom->documentElement->getAttribute('servicePath'); define("WebOrbServicesPath", realpath(WebOrb . $servicePath) . DIRECTORY_SEPARATOR); } if (file_exists(WebOrbServicesPath . "Weborb/Examples/Security/datbase.db")) { if (!($this->link = sqlite_open(WebOrbServicesPath . "Weborb/Examples/Security/datbase.db", 0666, $sqliteerror))) { throw new Exception($sqliteerror); } } else { if (!($this->link = sqlite_open(WebOrbServicesPath . "Weborb/Examples/Security/datbase.db", 0666, $sqliteerror))) { throw new Exception($sqliteerror); } sqlite_query($this->link, "CREATE TABLE Security ( Id INT, UserName VARCHAR(20), Password VARCHAR(20), Role VARCHAR(20) )"); sqlite_query($this->link, "INSERT INTO Security (Id, UserName, Password, Role) VALUES ( 1, 'joe', 'flexrocks', 'examplesuser' )"); sqlite_query($this->link, "INSERT INTO Security (Id, UserName, Password, Role) VALUES ( 2, 'bob', 'weborb', 'administrator' )"); sqlite_query($this->link, "CREATE TABLE Products ( Id INT, Name VARCHAR(20), Price NUMERIC )"); sqlite_query($this->link, "INSERT INTO Products (Id, Name, Price) VALUES ( 1, 'Laptop', 499 )"); sqlite_query($this->link, "INSERT INTO Products (Id, Name, Price) VALUES ( 2, 'Mouse', 20 )"); sqlite_query($this->link, "INSERT INTO Products (Id, Name, Price) VALUES ( 3, 'Keyboard', 10 )"); } }
/** * Non-persistent database connection. * * @param bool $persistent * * @return resource */ public function db_connect($persistent = false) { $error = null; $conn_id = $persistent === true ? sqlite_popen($this->database, 0666, $error) : sqlite_open($this->database, 0666, $error); isset($error) && log_message('error', $error); return $conn_id; }
/** * Method to invoke connection to RDBMS * * @return void */ private function connect() { $this->res_conn = @sqlite_open($this->db_name, 0666, $this->error); if ($this->error) { parent::showError(true); } }
/** * Database_SQLite::Database_SQLite * * Opens a SQLite database. */ function Database_SQLite($dsn) { if (file_exists($dsn)) { if (function_exists('sqlite_open')) { // Test to see if database is from SQLite version 2 $this->conn = @sqlite_open($dsn); } if (!is_resource($this->conn) && class_exists('PDO')) { $dir = dirname(__FILE__); require_once "{$dir}/pdo.php"; try { $this->pdo = new Database_PDO("sqlite:{$dsn}"); } catch (Exception $e) { try { $this->pdo = new Database_PDO("sqlite2:{$dsn}"); } catch (Exception $e) { trigger_error($e); return; } } } } else { $this->_empty_database = true; if (class_exists('PDO')) { $pdo_drivers = PDO::getAvailableDrivers(); if (in_array('sqlite', $pdo_drivers)) { $dir = dirname(__FILE__); require_once "{$dir}/pdo.php"; $this->pdo = new Database_PDO("sqlite:{$dsn}"); } else { $this->conn = sqlite_open($dsn); } } } }
function db_connect($connection_name = false) { if ($this->db) { return true; } // Choose what to connect to if ($connection_name && $GLOBALS['AR_DB_CONFIG'][$connection_name]) { $this->default = $GLOBALS['AR_DB_CONFIG'][$connection_name]; $this->db_connection = $connection_name; } elseif ($this->db_connection && $GLOBALS['AR_DB_CONFIG'][$this->db_connection]) { $this->default = $GLOBALS['AR_DB_CONFIG'][$this->db_connection]; } else { $this->default = $GLOBALS['AR_DB_CONFIG'][AR_DEFAULT_DB]; $this->db_connection = AR_DEFAULT_DB; } // Get outta here if we have no good setting if (!$this->default['database']) { die('Please setup database.ini'); } // Connect if ($this->db = sqlite_open($this->default['database'], 0666, $sqlite_error)) { // We're ok } else { die('Unable to connect to database: ' . $this->default['database'] . ' : ' . $this->default['database']); } return true; }
function connect($db_type, $var1 = false, $var2 = false, $var3 = false, $var4 = false, $var5 = '') { global $db_connected, $mysql_connect, $mysql_select_db, $sqlite_open, $db_type1, $db_prefix; $db_type1 = $db_type; $db_prefix = $var5; switch ($db_type) { case 'mysql': #var1 = db_host | var2 = db_user | var3 = db_pass | var4 = db_name | var5 = db_prefix $mysql_connect = mysql_connect($var1, $var2, $var3) or die("ERROR: 001"); if ($mysql_connect) { mysql_select_db($var4, $mysql_connect) or die("ERROR: 002"); mysql_query("SET NAMES 'utf8'"); $db_connected = true; } break; case 'mysqli': #var1 = db_host | var2 = db_user | var3 = db_pass | var4 = db_name | var5 = db_prefix $mysql_connect = mysqli_connect($var1, $var2, $var3, $var4) or die("ERROR: 001"); if ($mysql_connect) { mysqli_select_db($mysql_connect, $var4) or die("ERROR: 002"); mysqli_query($mysql_connect, "SET NAMES 'utf8'"); $db_connected = true; } break; case 'sqlite': #var1 = db_path $sqlite_open = sqlite_open($var1, 0666, $sqlite_error) or die("ERROR: 003"); sqlite_query($sqlite_open, "SET NAMES 'utf8'"); if ($sqlite_open) { $db_connected = true; } break; } }
function get_masters() { $db = sqlite_open("database.db") or die("failed to open/create the database"); $sql = "SELECT * FROM master"; $res = sqlite_query($db, $sql); return $res; }
function connect() { $this->connectionId = sqlite_open($this->config['database'], 0666, $error); if ($this->connectionId === false) { $this->_raiseError(); } }
function Connection() { if (file_exists(DB_FILE)) { $this->handler = sqlite_open(DB_FILE, 0666, $sqliteerror); } return $this->handler; }
/** * Connects to a database. * @return void * @throws DibiException */ public function connect(array &$config) { DibiConnection::alias($config, 'database', 'file'); $this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U'; $this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U'; $errorMsg = ''; if (isset($config['resource'])) { $this->connection = $config['resource']; } elseif (empty($config['persistent'])) { $this->connection = @sqlite_open($config['database'], 0666, $errorMsg); // intentionally @ } else { $this->connection = @sqlite_popen($config['database'], 0666, $errorMsg); // intentionally @ } if (!$this->connection) { throw new DibiDriverException($errorMsg); } $this->buffered = empty($config['unbuffered']); $this->dbcharset = empty($config['dbcharset']) ? 'UTF-8' : $config['dbcharset']; $this->charset = empty($config['charset']) ? 'UTF-8' : $config['charset']; if (strcasecmp($this->dbcharset, $this->charset) === 0) { $this->dbcharset = $this->charset = NULL; } }
public function __construct() { if (!extension_loaded('sqlite')) { throw new Exception('SQLite cache configured but "sqlite" PHP extension not installed.'); } $this->_db = sqlite_open($this->get_cache_directory() . '/' . $this->get_cache_name() . '.sqlite'); $this->_table = str_replace(array('.', '-'), '_', $this->get_cache_name()); // Check if we have a DB table corresponding to current cache name $result = sqlite_query($this->_db, "SELECT name FROM sqlite_master WHERE type='table' AND name='{$this->_table}'"); $tables = sqlite_fetch_array($result); if (count($tables) == 0 || $tables == false) { /** * Creating table for data */ sqlite_query($this->_db, "CREATE TABLE {$this->_table} (module VARCHAR(255), identifier VARCHAR(255), value TEXT);"); sqlite_query($this->_db, "CREATE INDEX {$this->_table}_identifier ON {$this->_table} (identifier);"); sqlite_query($this->_db, "CREATE INDEX {$this->_table}_module ON {$this->_table} (module);"); /** * Creating table for tags */ sqlite_query($this->_db, "CREATE TABLE {$this->_table}_tags (identifier VARCHAR(255), tag VARCHAR(255));"); sqlite_query($this->_db, "CREATE INDEX {$this->_table}_tags_i ON {$this->_table}_tags (identifier, tag);"); } parent::__construct(); }
/** * Non-persistent database connection * * @param bool $persistent * @return resource */ public function db_connect($persistent = FALSE) { $error = NULL; $conn_id = $persistent === TRUE ? sqlite_popen($this->database, 0666, $error) : sqlite_open($this->database, 0666, $error); isset($error) && log_message('error', $error); return $conn_id; }
/** * @param string */ public function __construct($dbfile) { $this->db = @sqlite_open($dbfile, 0664, $err); if ($err) { throw new IOException('Failed to open database: ' . $err); } }