本文整理汇总了PHP中sqlite_open函数的典型用法代码示例。如果您正苦于以下问题:PHP sqlite_open函数的具体用法?PHP sqlite_open怎么用?PHP sqlite_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sqlite_open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: db
protected static function db()
{
if (self::$db === false) {
self::$db = sqlite_open("app/temp/datadb.sqlite");
}
return self::$db;
}
示例2: __construct
/**
* @param $file
* @throws AdapterException
*/
public function __construct($file)
{
$this->_dbHandle = sqlite_open($file, 0666, $error);
if (!$this->_dbHandle) {
throw new AdapterException($error);
}
}
示例3: __construct
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;
}
}
示例4: SQL
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'");
}
}
示例5: Connect
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;
}
示例6: CreateDatabase
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;
}
示例7: prepareDB
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);
}
示例8: open
function open()
{
$this->db = sqlite_open($this->url, 0666, $sqliteerror);
if (!$this->db) {
die('接続失敗' . $sqliteerror);
}
}
示例9: sql_connect
/**
* {@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);
}
示例10: dbOpen_SQLite
/**
* 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;
}
示例11: init
/**
* 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;
}
示例12: db
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>");
}
}
示例13: dblayer
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;
}
}
示例14: SQLiteDatabase
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);
}
}
}
示例15: _connectDbOperation
protected function _connectDbOperation($db_params)
{
if (file_exists($db_params['name']))
return sqlite_open($db_params['name']);
else
return false;
}