diff --git a/php/database/albums_table.sql b/php/database/albums_table.sql index 55549e1..4f3b5c5 100644 --- a/php/database/albums_table.sql +++ b/php/database/albums_table.sql @@ -2,7 +2,7 @@ # Version 2.5 # ------------------------------------------------------------ -CREATE TABLE IF NOT EXISTS `lychee_albums` ( +CREATE TABLE IF NOT EXISTS `?` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(50) NOT NULL, `description` varchar(1000) DEFAULT '', diff --git a/php/database/log_table.sql b/php/database/log_table.sql index 5538cc2..800b00c 100644 --- a/php/database/log_table.sql +++ b/php/database/log_table.sql @@ -2,7 +2,7 @@ # Version 2.5 # ------------------------------------------------------------ -CREATE TABLE IF NOT EXISTS `lychee_log` ( +CREATE TABLE IF NOT EXISTS `?` ( `id` int(11) NOT NULL AUTO_INCREMENT, `time` int(11) NOT NULL, `type` varchar(11) NOT NULL, diff --git a/php/database/photos_table.sql b/php/database/photos_table.sql index ac4aa7f..929f808 100644 --- a/php/database/photos_table.sql +++ b/php/database/photos_table.sql @@ -2,7 +2,7 @@ # Version 2.5 # ------------------------------------------------------------ -CREATE TABLE IF NOT EXISTS `lychee_photos` ( +CREATE TABLE IF NOT EXISTS `?` ( `id` bigint(14) NOT NULL, `title` varchar(50) NOT NULL, `description` varchar(1000) DEFAULT '', diff --git a/php/database/settings_content.sql b/php/database/settings_content.sql index 7a7d20f..63d9a69 100644 --- a/php/database/settings_content.sql +++ b/php/database/settings_content.sql @@ -2,7 +2,7 @@ # Version 2.5 # ------------------------------------------------------------ -INSERT INTO `lychee_settings` (`key`, `value`) +INSERT INTO `?` (`key`, `value`) VALUES ('version',''), ('username',''), diff --git a/php/database/settings_table.sql b/php/database/settings_table.sql index 78d4f40..80eccce 100644 --- a/php/database/settings_table.sql +++ b/php/database/settings_table.sql @@ -2,7 +2,7 @@ # Version 2.5 # ------------------------------------------------------------ -CREATE TABLE IF NOT EXISTS `lychee_settings` ( +CREATE TABLE IF NOT EXISTS `?` ( `key` varchar(50) NOT NULL DEFAULT '', `value` varchar(200) DEFAULT '' ) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; \ No newline at end of file diff --git a/php/modules/Database.php b/php/modules/Database.php index 77ff6c9..439cf99 100755 --- a/php/modules/Database.php +++ b/php/modules/Database.php @@ -29,7 +29,8 @@ class Database extends Module { if (!Database::createDatabase($database, $name)) exit('Error: Could not create database!'); # Check tables - if (!$database->query('SELECT * FROM lychee_photos, lychee_albums, lychee_settings, lychee_log LIMIT 0;')) + $query = Database::prepare($database, 'SELECT * FROM ?, ?, ?, ? LIMIT 0', [LYCHEE_TABLE_PHOTOS, LYCHEE_TABLE_ALBUMS, LYCHEE_TABLE_SETTINGS, LYCHEE_TABLE_LOG]); + if (!$database->query($query)) if (!Database::createTables($database)) exit('Error: Could not create tables!'); return $database; @@ -140,30 +141,36 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); Module::dependencies(isset($database)); # Create log - if (!$database->query('SELECT * FROM lychee_log LIMIT 0;')) { + $exist = Database::prepare($database, 'SELECT * FROM ? LIMIT 0', [LYCHEE_TABLE_LOG]); + if (!$database->query($exist)) { # Read file $file = __DIR__ . '/../database/log_table.sql'; $query = @file_get_contents($file); - # Create table if (!isset($query)||$query===false) return false; + + # Create table + $query = Database::prepare($database, $query, [LYCHEE_TABLE_LOG]); if (!$database->query($query)) return false; } # Create settings - if (!$database->query('SELECT * FROM lychee_settings LIMIT 0;')) { + $exist = Database::prepare($database, 'SELECT * FROM ? LIMIT 0', [LYCHEE_TABLE_SETTINGS]); + if (!$database->query($exist)) { # Read file $file = __DIR__ . '/../database/settings_table.sql'; $query = @file_get_contents($file); - # Create table if (!isset($query)||$query===false) { Log::error($database, __METHOD__, __LINE__, 'Could not load query for lychee_settings'); return false; } + + # Create table + $query = Database::prepare($database, $query, [LYCHEE_TABLE_SETTINGS]); if (!$database->query($query)) { Log::error($database, __METHOD__, __LINE__, $database->error); return false; @@ -173,11 +180,13 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); $file = __DIR__ . '/../database/settings_content.sql'; $query = @file_get_contents($file); - # Add content if (!isset($query)||$query===false) { Log::error($database, __METHOD__, __LINE__, 'Could not load content-query for lychee_settings'); return false; } + + # Add content + $query = Database::prepare($database, $query, [LYCHEE_TABLE_SETTINGS]); if (!$database->query($query)) { Log::error($database, __METHOD__, __LINE__, $database->error); return false; @@ -186,17 +195,20 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); } # Create albums - if (!$database->query('SELECT * FROM lychee_albums LIMIT 0;')) { + $exist = Database::prepare($database, 'SELECT * FROM ? LIMIT 0', [LYCHEE_TABLE_ALBUMS]); + if (!$database->query($exist)) { # Read file $file = __DIR__ . '/../database/albums_table.sql'; $query = @file_get_contents($file); - # Create table if (!isset($query)||$query===false) { Log::error($database, __METHOD__, __LINE__, 'Could not load query for lychee_albums'); return false; } + + # Create table + $query = Database::prepare($database, $query, [LYCHEE_TABLE_ALBUMS]); if (!$database->query($query)) { Log::error($database, __METHOD__, __LINE__, $database->error); return false; @@ -205,17 +217,20 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); } # Create photos - if (!$database->query('SELECT * FROM lychee_photos LIMIT 0;')) { + $exist = Database::prepare($database, 'SELECT * FROM ? LIMIT 0', [LYCHEE_TABLE_PHOTOS]); + if (!$database->query($exist)) { # Read file $file = __DIR__ . '/../database/photos_table.sql'; $query = @file_get_contents($file); - # Create table if (!isset($query)||$query===false) { Log::error($database, __METHOD__, __LINE__, 'Could not load query for lychee_photos'); return false; } + + # Create table + $query = Database::prepare($database, $query, [LYCHEE_TABLE_PHOTOS]); if (!$database->query($query)) { Log::error($database, __METHOD__, __LINE__, $database->error); return false;