/** * Initialize the database for the registry * * Registry information that must be stored: * * - A list of installed packages * - the files in each package * - known channels */ function create(\SQLite3 $database) { $database->enableExceptions(true); try { $this->_create($database); } catch (\Exception $e) { $database->enableExceptions(false); @$database->exec('ROLLBACK'); throw new \Pyrus\Registry\Exception('Cannot initialize SQLite3 registry: ' . $e->getMessage(), $e); } $database->enableExceptions(false); }
<?php if (!class_exists('SQLite3')) { echo "install sqlite3 first, forexample: 'apt-get install php5-sqlite3'"; die("SQLite3 class not found!"); } $params = array(); if (isset($argv)) { $params = $argv; } $data = array(); $dir = "/var/www/src/grep"; $file = realpath(dirname(__FILE__)) . "/database.db"; // Open database $db = new SQLite3($file); $db->enableExceptions(true); /* TOOL SCAN DIRECTORY AND GET ALL FILES */ function getDirContents($dir, &$results = array()) { $files = scandir($dir); foreach ($files as $key => $value) { $path = realpath($dir . DIRECTORY_SEPARATOR . $value); if (!is_dir($path)) { $results[] = array('path' => $path, 'ext' => strtolower(pathinfo($path, PATHINFO_EXTENSION)), 'type' => "FILE"); } else { if ($value != "." && $value != "..") { $results[] = array('path' => $path, 'ext' => "", 'type' => "DIR"); getDirContents($path, $results); } } }
<?php $db = new SQLite3(':memory:'); var_dump($db->enableExceptions(true)); try { $db->query("SELECT * FROM non_existent_table"); } catch (Exception $e) { echo $e->getMessage() . PHP_EOL; } var_dump($db->enableExceptions(false)); $db->query("SELECT * FROM non_existent_table"); var_dump($db->enableExceptions("wrong_type", "wrong_type")); echo "Closing database\n"; var_dump($db->close()); echo "Done\n";