Skip to content

Instantly share code, notes, and snippets.

@Jmainguy
Created January 16, 2017 20:52
Show Gist options
  • Save Jmainguy/e54d5f3ad25dfe2c6828067dcd25246d to your computer and use it in GitHub Desktop.
Save Jmainguy/e54d5f3ad25dfe2c6828067dcd25246d to your computer and use it in GitHub Desktop.
root@d5fe1c33ffb4:/var/www/html# php index.php
Fatal error: Uncaught Exception: Unable to open database: unable to open database file in /var/www/html/index.php:11
Stack trace:
#0 /var/www/html/index.php(11): SQLite3->__construct('/var/www/html/w...', 1)
#1 /var/www/html/index.php(36): ServersDb->__construct()
#2 {main}
thrown in /var/www/html/index.php on line 11
root@d5fe1c33ffb4:/var/www/html# pwd
/var/www/html
root@d5fe1c33ffb4:/var/www/html# ls
index.php web.db
root@d5fe1c33ffb4:/var/www/html# cat index.php
<?php
define('DB_FILE', '/var/www/html/web.db'); // replace this with web.db full path
/**
* @class ServersDb
*/
class ServersDb extends SQLite3 {
public function __construct() {
parent::__construct(DB_FILE, SQLITE3_OPEN_READONLY);
}
public function __destruct() {
$this->close();
}
public function getAll() {
$servers = array();
$games = $this->query('select * from Games');
while (true) {
$game = $games->fetchArray(SQLITE3_ASSOC);
if (empty($game)) {
break;
}
$servers[] = $game;
}
return $servers;
}
}
$serversDb = new ServersDb();
header('Content-Type: application/json');
echo preg_replace('/(\\\u000\d|\\\t|\\\b)/', '', json_encode($serversDb->getAll()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment