diff options
Diffstat (limited to 'includes')
22 files changed, 514 insertions, 514 deletions
diff --git a/includes/authentication.php b/includes/authentication.php index fb892e647c..7fee9ec0c1 100644 --- a/includes/authentication.php +++ b/includes/authentication.php @@ -238,22 +238,22 @@ function userAutoAccept($user_id=WT_USER_ID) { // Get the full name for a user function getUserFullName($user_id) { - return WT_DB::prepare("SELECT real_name FROM ##user WHERE user_id=?")->execute(array($user_id))->fetchOne(); + return WT_DB::prepare("SELECT real_name FROM `##user` WHERE user_id=?")->execute(array($user_id))->fetchOne(); } // Set the full name for a user function setUserFullName($user_id, $real_name) { - return WT_DB::prepare("UPDATE ##user SET real_name=? WHERE user_id=?")->execute(array($real_name, $user_id)); + return WT_DB::prepare("UPDATE `##user` SET real_name=? WHERE user_id=?")->execute(array($real_name, $user_id)); } // Get the email for a user function getUserEmail($user_id) { - return WT_DB::prepare("SELECT email FROM ##user WHERE user_id=?")->execute(array($user_id))->fetchOne(); + return WT_DB::prepare("SELECT email FROM `##user` WHERE user_id=?")->execute(array($user_id))->fetchOne(); } // Set the email for a user function setUserEmail($user_id, $email) { - return WT_DB::prepare("UPDATE ##user SET email=? WHERE user_id=?")->execute(array($email, $user_id)); + return WT_DB::prepare("UPDATE `##user` SET email=? WHERE user_id=?")->execute(array($email, $user_id)); } // Get the root person for this gedcom @@ -281,7 +281,7 @@ function AddToLog($log_message, $log_type='error') { global $argc; WT_DB::prepare( - "INSERT INTO ##log (log_type, log_message, ip_address, user_id, gedcom_id) VALUES (?, ?, ?, ?, ?)" + "INSERT INTO `##log` (log_type, log_message, ip_address, user_id, gedcom_id) VALUES (?, ?, ?, ?, ?)" )->execute(array( $log_type, $log_message, @@ -297,7 +297,7 @@ function AddToSearchLog($log_message, $geds) { $all_geds=get_all_gedcoms(); foreach ($geds as $ged_id=>$ged_name) { WT_DB::prepare( - "INSERT INTO ##log (log_type, log_message, ip_address, user_id, gedcom_id) VALUES ('search', ?, ?, ?, ?)" + "INSERT INTO `##log` (log_type, log_message, ip_address, user_id, gedcom_id) VALUES ('search', ?, ?, ?, ?)" )->execute(array( (count($all_geds)==count($geds) ? 'Global search: ' : 'Gedcom search: ').$log_message, $_SERVER['REMOTE_ADDR'], @@ -311,7 +311,7 @@ function AddToSearchLog($log_message, $geds) { //-- requires a string to add into the changelog-file function AddToChangeLog($log_message, $ged_id=WT_GED_ID) { WT_DB::prepare( - "INSERT INTO ##log (log_type, log_message, ip_address, user_id, gedcom_id) VALUES ('change', ?, ?, ?, ?)" + "INSERT INTO `##log` (log_type, log_message, ip_address, user_id, gedcom_id) VALUES ('change', ?, ?, ?, ?)" )->execute(array( $log_message, $_SERVER['REMOTE_ADDR'], @@ -412,7 +412,7 @@ function addMessage($message) { if (empty($message["created"])) $message["created"] = gmdate ("D, d M Y H:i:s T"); if ($WT_STORE_MESSAGES && ($message["method"]!="messaging3" && $message["method"]!="mailto" && $message["method"]!="none")) { - WT_DB::prepare("INSERT INTO ##message (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)") + WT_DB::prepare("INSERT INTO `##message` (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)") ->execute(array($message["from"], $_SERVER['REMOTE_ADDR'], get_user_id($message["to"]), $message["subject"], $message["body"])); } if ($message["method"]!="messaging") { @@ -449,14 +449,14 @@ function addMessage($message) { //----------------------------------- deleteMessage //-- deletes a message in the database function deleteMessage($message_id) { - return (bool)WT_DB::prepare("DELETE FROM ##message WHERE message_id=?")->execute(array($message_id)); + return (bool)WT_DB::prepare("DELETE FROM `##message` WHERE message_id=?")->execute(array($message_id)); } //----------------------------------- getUserMessages //-- Return an array of a users messages function getUserMessages($user_id) { $rows= - WT_DB::prepare("SELECT message_id, sender, subject, body, created FROM ##message WHERE user_id=? ORDER BY message_id DESC") + WT_DB::prepare("SELECT message_id, sender, subject, body, created FROM `##message` WHERE user_id=? ORDER BY message_id DESC") ->execute(array($user_id)) ->fetchAll(); @@ -483,15 +483,15 @@ function getUserMessages($user_id) { * @param boolean $setdefault if true tells the program to also set these blocks as the blocks for the defaultuser */ function setBlocks($username, $ublocks, $setdefault=false) { - WT_DB::prepare("DELETE FROM ##blocks WHERE b_username=? AND b_name!=?") + WT_DB::prepare("DELETE FROM `##blocks` WHERE b_username=? AND b_name!=?") ->execute(array($username, 'faq')); if ($setdefault) { - WT_DB::prepare("DELETE FROM ##blocks WHERE b_username=?") + WT_DB::prepare("DELETE FROM `##blocks` WHERE b_username=?") ->execute(array('defaultuser')); } - $statement=WT_DB::prepare("INSERT INTO ##blocks (b_id, b_username, b_location, b_order, b_name, b_config) VALUES (?, ?, ?, ?, ?, ?)"); + $statement=WT_DB::prepare("INSERT INTO `##blocks` (b_id, b_username, b_location, b_order, b_name, b_config) VALUES (?, ?, ?, ?, ?, ?)"); foreach($ublocks["main"] as $order=>$block) { $statement->execute(array(get_next_id("blocks", "b_id"), $username, 'main', $order, $block[0], serialize($block[1]))); @@ -526,22 +526,22 @@ function addNews($news) { // In case news items are added from usermigrate, it will also contain an ID. // So we check first if the ID exists in the database. If not, insert instead of update. $exists= - WT_DB::prepare("SELECT 1 FROM ##news where n_id=?") + WT_DB::prepare("SELECT 1 FROM `##news` where n_id=?") ->execute(array($news["id"])) ->fetchOne(); if (!$exists) { return (bool) - WT_DB::prepare("INSERT INTO ##news (n_id, n_username, n_date, n_title, n_text) VALUES (?, ? ,? ,? ,?)") + WT_DB::prepare("INSERT INTO `##news` (n_id, n_username, n_date, n_title, n_text) VALUES (?, ? ,? ,? ,?)") ->execute(array($news["id"], $news["username"], $news["date"], $news["title"], $news["text"])); } else { return (bool) - WT_DB::prepare("UPDATE ##news SET n_date=?, n_title=? , n_text=? WHERE n_id=?") + WT_DB::prepare("UPDATE `##news` SET n_date=?, n_title=? , n_text=? WHERE n_id=?") ->execute(array($news["date"], $news["title"], $news["text"], $news["id"])); } } else { return (bool) - WT_DB::prepare("INSERT INTO ##news (n_id, n_username, n_date, n_title, n_text) VALUES (?, ? ,? ,? ,?)") + WT_DB::prepare("INSERT INTO `##news` (n_id, n_username, n_date, n_title, n_text) VALUES (?, ? ,? ,? ,?)") ->execute(array(get_next_id("news", "n_id"), $news["username"], $news["date"], $news["title"], $news["text"])); } } @@ -553,7 +553,7 @@ function addNews($news) { * @param int $news_id the id number of the news item to delete */ function deleteNews($news_id) { - return (bool)WT_DB::prepare("DELETE FROM ##news WHERE n_id=?")->execute(array($news_id)); + return (bool)WT_DB::prepare("DELETE FROM `##news` WHERE n_id=?")->execute(array($news_id)); } /** @@ -563,7 +563,7 @@ function deleteNews($news_id) { */ function getUserNews($username) { $rows= - WT_DB::prepare("SELECT * FROM ##news WHERE n_username=? ORDER BY n_date DESC") + WT_DB::prepare("SELECT * FROM `##news` WHERE n_username=? ORDER BY n_date DESC") ->execute(array($username)) ->fetchAll(); @@ -588,7 +588,7 @@ function getUserNews($username) { */ function getNewsItem($news_id) { $row= - WT_DB::prepare("SELECT * FROM ##news WHERE n_id=?") + WT_DB::prepare("SELECT * FROM `##news` WHERE n_id=?") ->execute(array($news_id)) ->fetchOneRow(); diff --git a/includes/classes/class_gedcomrecord.php b/includes/classes/class_gedcomrecord.php index 27a02b9a2d..37d4e70e31 100644 --- a/includes/classes/class_gedcomrecord.php +++ b/includes/classes/class_gedcomrecord.php @@ -383,7 +383,7 @@ class GedcomRecord { function isMarkedDeleted() { $tmp=WT_DB::prepare( "SELECT new_gedcom". - " FROM ##change". + " FROM `##change`". " WHERE status='pending' AND gedcom_id=? AND xref=?". " ORDER BY change_id desc". " LIMIT 1" diff --git a/includes/classes/class_media.php b/includes/classes/class_media.php index f96bb5bf06..43f74626c1 100644 --- a/includes/classes/class_media.php +++ b/includes/classes/class_media.php @@ -262,7 +262,7 @@ class Media extends GedcomRecord { */ static function in_obje_list($obje) { return - WT_DB::prepare("SELECT m_media FROM ##media WHERE m_file=? AND m_titl LIKE ? AND m_gedfile=?") + WT_DB::prepare("SELECT m_media FROM `##media` WHERE m_file=? AND m_titl LIKE ? AND m_gedfile=?") ->execute(array($obje->file, $obje->title, WT_GED_ID)) ->fetchOne(); } diff --git a/includes/classes/class_menubar.php b/includes/classes/class_menubar.php index 1700caae41..946c50ec79 100644 --- a/includes/classes/class_menubar.php +++ b/includes/classes/class_menubar.php @@ -891,7 +891,7 @@ class MenuBar $submenu->addOnclick("return helpPopup('help_contents_help');"); $menu->addSubmenu($submenu); //-- faq sub menu - if (array_key_exists('faq', WT_Module::getActiveBlocks()) && WT_DB::prepare("SELECT COUNT(*) FROM ##block WHERE module_name='faq'")->fetchOne()) { + if (array_key_exists('faq', WT_Module::getActiveBlocks()) && WT_DB::prepare("SELECT COUNT(*) FROM `##block` WHERE module_name='faq'")->fetchOne()) { $submenu = new Menu(i18n::translate('FAQ'), "module.php?mod=faq&mod_action=show"); if (!empty($WT_IMAGES["menu_help"]["small"])) diff --git a/includes/classes/class_module.php b/includes/classes/class_module.php index 96a161ab88..189e0e42bd 100644 --- a/includes/classes/class_module.php +++ b/includes/classes/class_module.php @@ -104,7 +104,7 @@ abstract class WT_Module { final static public function getActiveModules() { $module_names=WT_DB::prepare( "SELECT module_name". - " FROM ##module". + " FROM `##module`". " WHERE status='enabled'". " ORDER BY module_name" )->fetchOneColumn(); @@ -117,8 +117,8 @@ abstract class WT_Module { } else { // Module has been deleted from disk? Remove it from the database. AddToLog("Module {$module_name} has been deleted from disk - deleting from database", 'config'); - WT_DB::prepare("DELETE FROM ##module_privacy WHERE module_name=?")->execute(array($module_name)); - WT_DB::prepare("DELETE FROM ##module WHERE module_name=?")->execute(array($module_name)); + WT_DB::prepare("DELETE FROM `##module_privacy` WHERE module_name=?")->execute(array($module_name)); + WT_DB::prepare("DELETE FROM `##module` WHERE module_name=?")->execute(array($module_name)); } } return $array; @@ -127,8 +127,8 @@ abstract class WT_Module { final static private function getActiveModulesByComponent($component, $ged_id, $access_level) { $module_names=WT_DB::prepare( "SELECT module_name". - " FROM ##module". - " JOIN ##module_privacy USING (module_name)". + " FROM `##module`". + " JOIN `##module_privacy` USING (module_name)". " WHERE gedcom_id=? AND component=? AND status='enabled' AND access_level>=?". " ORDER BY CASE component WHEN 'menu' THEN menu_order WHEN 'sidebar' THEN sidebar_order WHEN 'tab' THEN tab_order ELSE module_name END" )->execute(array($ged_id, $component, $access_level))->fetchOneColumn(); @@ -141,8 +141,8 @@ abstract class WT_Module { } else { // Module has been deleted from disk? Remove it from the database. AddToLog("Module {$module_name} has been deleted from disk - deleting from database", 'config'); - WT_DB::prepare("DELETE FROM ##module_privacy WHERE module_name=?")->execute(array($module_name)); - WT_DB::prepare("DELETE FROM ##module WHERE module_name=?")->execute(array($module_name)); + WT_DB::prepare("DELETE FROM `##module_privacy` WHERE module_name=?")->execute(array($module_name)); + WT_DB::prepare("DELETE FROM `##module` WHERE module_name=?")->execute(array($module_name)); } } if ($component!='menu' && $component!='sidebar' && $component!='tab') { @@ -259,7 +259,7 @@ abstract class WT_Module { foreach (self::getInstalledModules() as $name=>$module) { if ($module instanceof WT_Module_Menu) { $module->sort=WT_DB::prepare( - "SELECT menu_order FROM ##module WHERE module_name=?" + "SELECT menu_order FROM `##module` WHERE module_name=?" )->execute(array($module->getName()))->fetchOne(); $modules[$name]=$module; } @@ -285,7 +285,7 @@ abstract class WT_Module { foreach (self::getInstalledModules() as $name=>$module) { if ($module instanceof WT_Module_Sidebar) { $module->sort=WT_DB::prepare( - "SELECT sidebar_order FROM ##module WHERE module_name=?" + "SELECT sidebar_order FROM `##module` WHERE module_name=?" )->execute(array($module->getName()))->fetchOne(); $modules[$name]=$module; } @@ -300,7 +300,7 @@ abstract class WT_Module { foreach (self::getInstalledModules() as $name=>$module) { if ($module instanceof WT_Module_Tab) { $module->sort=WT_DB::prepare( - "SELECT tab_order FROM ##module WHERE module_name=?" + "SELECT tab_order FROM `##module` WHERE module_name=?" )->execute(array($module->getName()))->fetchOne(); $modules[$name]=$module; } @@ -323,7 +323,7 @@ abstract class WT_Module { // final static public function setDefaultAccess($ged_id) { foreach (self::getInstalledModules() as $module) { - WT_DB::prepare("INSERT IGNORE INTO ##module (module_name, menu_order, sidebar_order, tab_order) VALUES (?, ?, ?, ?)") + WT_DB::prepare("INSERT IGNORE INTO `##module` (module_name, menu_order, sidebar_order, tab_order) VALUES (?, ?, ?, ?)") ->execute(array( $module->getName(), $module instanceof WT_Module_Menu ? $module->defaultMenuOrder () : null, @@ -331,40 +331,40 @@ abstract class WT_Module { $module instanceof WT_Module_Tab ? $module->defaultTabOrder () : null )); } - WT_DB::prepare("DELETE FROM ##module_privacy WHERE gedcom_id=?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##module_privacy` WHERE gedcom_id=?")->execute(array($ged_id)); foreach (self::getInstalledMenus() as $module) { WT_DB::prepare( - "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'menu', ?)" + "INSERT INTO `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'menu', ?)" )->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel())); } foreach (self::getInstalledSidebars() as $module) { WT_DB::prepare( - "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'sidebar', ?)" + "INSERT INTO `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'sidebar', ?)" )->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel())); } foreach (self::getInstalledTabs() as $module) { WT_DB::prepare( - "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'tab', ?)" + "INSERT INTO `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'tab', ?)" )->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel())); } foreach (self::getInstalledBlocks() as $module) { WT_DB::prepare( - "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'block', ?)" + "INSERT INTO `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'block', ?)" )->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel())); } foreach (self::getInstalledCharts() as $module) { WT_DB::prepare( - "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'charts', ?)" + "INSERT INTO `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'charts', ?)" )->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel())); } foreach (self::getInstalledReports() as $module) { WT_DB::prepare( - "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'report', ?)" + "INSERT INTO `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'report', ?)" )->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel())); } foreach (self::getInstalledThemes() as $module) { WT_DB::prepare( - "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'theme', ?)" + "INSERT INTO `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'theme', ?)" )->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel())); } } diff --git a/includes/classes/class_reportbase.php b/includes/classes/class_reportbase.php index 5d4f9dc06b..f19d2cbfe0 100644 --- a/includes/classes/class_reportbase.php +++ b/includes/classes/class_reportbase.php @@ -3190,10 +3190,10 @@ function ListSHandler($attrs) { case "pending": $rows=WT_DB::prepare( "SELECT CASE new_gedcom WHEN '' THEN old_gedcom ELSE new_gedcom END AS gedcom". - " FROM ##change". + " FROM `##change`". " WHERE (xref, change_id) IN (". " SELECT xref, MAX(change_id)". - " FROM ##change". + " FROM `##change`". " WHERE status='pending' AND gedcom_id=?". " GROUP BY xref". " )" @@ -3215,7 +3215,7 @@ function ListSHandler($attrs) { $value=preg_replace('/\$(\w+)/e', '$vars["\\1"]["id"]', $value); // Convert the various filters into SQL if (preg_match('/^(\w+):DATE (LTE|GTE) (.+)$/', $value, $match)) { - $sql_join[]="JOIN ##dates AS {$attr} ON ({$attr}.d_file={$sql_col_prefix}file AND {$attr}.d_gid={$sql_col_prefix}id)"; + $sql_join[]="JOIN `##dates` AS {$attr} ON ({$attr}.d_file={$sql_col_prefix}file AND {$attr}.d_gid={$sql_col_prefix}id)"; $sql_where[]="{$attr}.d_fact='{$match[1]}'"; $date=new GedcomDate($match[3]); if ($match[2]=="LTE") { @@ -3231,7 +3231,7 @@ function ListSHandler($attrs) { } elseif (($listname=="individual") && (preg_match('/^NAME CONTAINS (.*)$/', $value, $match))){ // Do nothing, unless you have to if (($match[1] != "") or ($sortby=="NAME")){ - $sql_join[]="JOIN ##name AS {$attr} ON (n_file={$sql_col_prefix}file AND n_id={$sql_col_prefix}id)"; + $sql_join[]="JOIN `##name` AS {$attr} ON (n_file={$sql_col_prefix}file AND n_id={$sql_col_prefix}id)"; // Search the DB only if there is any name supplied if ($match[1] != ""){ $names = explode(" ", $match[1]); @@ -3248,8 +3248,8 @@ function ListSHandler($attrs) { unset($attrs[$attr]); // This filter has been fully processed } elseif (($listname=="family") && (preg_match('/^NAME CONTAINS (.+)$/', $value, $match))) { // Eventually, family "names" will be stored in pgv_name. Until then, an extra is needed.... - $sql_join[]="JOIN ##link AS {$attr}a ON ({$attr}a.l_file={$sql_col_prefix}file AND {$attr}a.l_from={$sql_col_prefix}id)"; - $sql_join[]="JOIN ##name AS {$attr}b ON ({$attr}b.n_file={$sql_col_prefix}file AND n_id={$sql_col_prefix}id)"; + $sql_join[]="JOIN `##link` AS {$attr}a ON ({$attr}a.l_file={$sql_col_prefix}file AND {$attr}a.l_from={$sql_col_prefix}id)"; + $sql_join[]="JOIN `##name` AS {$attr}b ON ({$attr}b.n_file={$sql_col_prefix}file AND n_id={$sql_col_prefix}id)"; $sql_where[]="{$attr}a.l_type=IN ('HUSB, 'WIFE')"; $sql_where[]="{$attr}.n_full LIKE ".WT_DB::quote(utf8_strtoupper("%{$match[1]}%")); if ($sortby=="NAME") { @@ -3258,8 +3258,8 @@ function ListSHandler($attrs) { } unset($attrs[$attr]); // This filter has been fully processed } elseif (preg_match('/^(?:\w+):PLAC CONTAINS (.+)$/', $value, $match)) { - $sql_join[]="JOIN ##places AS {$attr}a ON ({$attr}a.p_file={$sql_col_prefix}file)"; - $sql_join[]="JOIN ##placelinks AS {$attr}b ON ({$attr}a.p_file={$attr}b.pl_file AND {$attr}b.pl_p_id={$attr}a.p_id AND {$attr}b.pl_gid={$sql_col_prefix}id)"; + $sql_join[]="JOIN `##places` AS {$attr}a ON ({$attr}a.p_file={$sql_col_prefix}file)"; + $sql_join[]="JOIN `##placelinks` AS {$attr}b ON ({$attr}a.p_file={$attr}b.pl_file AND {$attr}b.pl_p_id={$attr}a.p_id AND {$attr}b.pl_gid={$sql_col_prefix}id)"; $sql_where[]="{$attr}a.p_place LIKE ".WT_DB::quote(utf8_strtoupper("%{$match[1]}%")); // Don't unset this filter. This is just the first primary PLAC filter to reduce the returned list from the DB } diff --git a/includes/classes/class_serviceclient.php b/includes/classes/class_serviceclient.php index acb6f168f3..f14c33d646 100644 --- a/includes/classes/class_serviceclient.php +++ b/includes/classes/class_serviceclient.php @@ -628,7 +628,7 @@ class ServiceClient extends GedcomRecord { //-- check if the link already exists $gid=get_remote_id($remote); if (empty($gid)) { - WT_DB::prepare("INSERT INTO ##remotelinks (r_gid, r_linkid, r_file) VALUES (? ,? ,?)") + WT_DB::prepare("INSERT INTO `##remotelinks` (r_gid, r_linkid, r_file) VALUES (? ,? ,?)") ->execute(array($local, $remote, get_id_from_gedcom($GEDCOM))); } } diff --git a/includes/classes/class_stats.php b/includes/classes/class_stats.php index 1cefac05ae..df5115cf1c 100644 --- a/includes/classes/class_stats.php +++ b/includes/classes/class_stats.php @@ -277,7 +277,7 @@ class stats { function gedcomUpdated() { $row= - WT_DB::prepareLimit("SELECT d_year, d_month, d_day FROM ##dates WHERE d_file=? AND d_fact=? ORDER BY d_julianday1 DESC, d_type", 1) + WT_DB::prepareLimit("SELECT d_year, d_month, d_day FROM `##dates` WHERE d_file=? AND d_fact=? ORDER BY d_julianday1 DESC, d_type", 1) ->execute(array($this->_ged_id, 'CHAN')) ->fetchOneRow(); if ($row) { @@ -374,13 +374,13 @@ class stats { function totalIndividuals() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##individuals` WHERE i_file=?") ->execute(array($this->_ged_id)) ->fetchOne(); } function totalIndisWithSources() { - $rows=self::_runSQL("SELECT COUNT(DISTINCT i_id) AS tot FROM ##link, ##individuals WHERE i_id=l_from AND i_file=l_file AND l_file=".$this->_ged_id." AND l_type='SOUR'"); + $rows=self::_runSQL("SELECT COUNT(DISTINCT i_id) AS tot FROM `##link`, `##individuals` WHERE i_id=l_from AND i_file=l_file AND l_file=".$this->_ged_id." AND l_type='SOUR'"); return $rows[0]['tot']; } @@ -413,13 +413,13 @@ class stats { function totalFamilies() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##families WHERE f_file=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##families` WHERE f_file=?") ->execute(array($this->_ged_id)) ->fetchOne(); } function totalFamsWithSources() { - $rows=self::_runSQL("SELECT COUNT(DISTINCT f_id) AS tot FROM ##link, ##families WHERE f_id=l_from AND f_file=l_file AND l_file=".$this->_ged_id." AND l_type='SOUR'"); + $rows=self::_runSQL("SELECT COUNT(DISTINCT f_id) AS tot FROM `##link`, `##families` WHERE f_id=l_from AND f_file=l_file AND l_file=".$this->_ged_id." AND l_type='SOUR'"); return $rows[0]['tot']; } @@ -452,7 +452,7 @@ class stats { function totalSources() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##sources WHERE s_file=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##sources` WHERE s_file=?") ->execute(array($this->_ged_id)) ->fetchOne(); } @@ -463,7 +463,7 @@ class stats { function totalNotes() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##other WHERE o_type=? AND o_file=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##other` WHERE o_type=? AND o_file=?") ->execute(array('NOTE', $this->_ged_id)) ->fetchOne(); } @@ -474,7 +474,7 @@ class stats { function totalOtherRecords() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##other WHERE o_type<>? AND o_file=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##other` WHERE o_type<>? AND o_file=?") ->execute(array('NOTE', $this->_ged_id)) ->fetchOne(); } @@ -496,7 +496,7 @@ class stats { } $vars[]=$this->_ged_id; return (int) - WT_DB::prepare("SELECT COUNT({$distinct} n_surn) FROM ##name WHERE n_surn {$opt} AND n_file=?") + WT_DB::prepare("SELECT COUNT({$distinct} n_surn) FROM `##name` WHERE n_surn {$opt} AND n_file=?") ->execute($vars) ->fetchOne(); } @@ -514,13 +514,13 @@ class stats { } $vars[]=$this->_ged_id; return (int) - WT_DB::prepare("SELECT COUNT({$distinct} n_givn) FROM ##name WHERE n_givn {$opt} AND n_file=?") + WT_DB::prepare("SELECT COUNT({$distinct} n_givn) FROM `##name` WHERE n_givn {$opt} AND n_file=?") ->execute($vars) ->fetchOne(); } function totalEvents($params = null) { - $sql="SELECT COUNT(*) AS tot FROM ##dates WHERE d_file=?"; + $sql="SELECT COUNT(*) AS tot FROM `##dates` WHERE d_file=?"; $vars=array($this->_ged_id); $no_types=array('HEAD', 'CHAN'); @@ -587,7 +587,7 @@ class stats { function totalSexMales() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_sex=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##individuals` WHERE i_file=? AND i_sex=?") ->execute(array($this->_ged_id, 'M')) ->fetchOne(); } @@ -598,7 +598,7 @@ class stats { function totalSexFemales() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_sex=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##individuals` WHERE i_file=? AND i_sex=?") ->execute(array($this->_ged_id, 'F')) ->fetchOne(); } @@ -609,7 +609,7 @@ class stats { function totalSexUnknown() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_sex=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##individuals` WHERE i_file=? AND i_sex=?") ->execute(array($this->_ged_id, 'U')) ->fetchOne(); } @@ -655,7 +655,7 @@ class stats { function totalLiving() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_isdead=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##individuals` WHERE i_file=? AND i_isdead=?") ->execute(array($this->_ged_id, 0)) ->fetchOne(); } @@ -666,7 +666,7 @@ class stats { function totalDeceased() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_isdead=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##individuals` WHERE i_file=? AND i_isdead=?") ->execute(array($this->_ged_id, 1)) ->fetchOne(); } @@ -677,7 +677,7 @@ class stats { function totalMortalityUnknown() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_isdead=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##individuals` WHERE i_file=? AND i_isdead=?") ->execute(array($this->_ged_id, -1)) ->fetchOne(); } @@ -687,7 +687,7 @@ class stats { } function mortalityUnknown() { - $rows=self::_runSQL("SELECT i_id AS id FROM ##individuals WHERE i_file={$this->_ged_id} AND i_isdead=-1"); + $rows=self::_runSQL("SELECT i_id AS id FROM `##individuals` WHERE i_file={$this->_ged_id} AND i_isdead=-1"); if (!isset($rows[0])) {return '';} return $rows; } @@ -749,7 +749,7 @@ class stats { if (!$MULTI_MEDIA || !in_array($type, self::$_media_types) && $type != 'all' && $type != 'unknown') { return 0; } - $sql="SELECT COUNT(*) AS tot FROM ##media WHERE m_gedfile=?"; + $sql="SELECT COUNT(*) AS tot FROM `##media` WHERE m_gedfile=?"; $vars=array($this->_ged_id); if ($type != 'all') { @@ -877,7 +877,7 @@ class stats { } $rows=self::_runSQL('' ."SELECT d_year, d_type, d_fact, d_gid" - ." FROM ##dates" + ." FROM `##dates`" ." WHERE d_file={$this->_ged_id} AND d_fact IN ({$query_field}) AND d_julianday1<>0" ." ORDER BY d_julianday1 {$life_dir}, d_type", 1 @@ -891,7 +891,7 @@ class stats { .' d2.d_fact,' .' d2.d_gid' .' FROM' - ." ##dates AS d2" + ." `##dates` AS d2" .' WHERE' ." d2.d_file={$this->_ged_id} AND" ." d2.d_fact IN ({$query_field}) AND" @@ -899,12 +899,12 @@ class stats { .' SELECT' ." {$dmod}(d_julianday1)" .' FROM' - ." ##dates" + ." `##dates`" .' JOIN (' .' SELECT' .' d1.d_gid, MIN(d1.d_julianday1) as date' .' FROM' - ." ##dates AS d1" + ." `##dates` AS d1" .' WHERE' ." d1.d_fact IN ({$query_field}) AND" ." d1.d_file={$this->_ged_id} AND" @@ -959,13 +959,13 @@ class stats { if ($fact) { if ($what=='INDI') { $rows= - WT_DB::prepare("SELECT i_gedcom AS ged FROM ##individuals WHERE i_file=?") + WT_DB::prepare("SELECT i_gedcom AS ged FROM `##individuals` WHERE i_file=?") ->execute(array($this->_ged_id)) ->fetchAll(); } else if ($what=='FAM') { $rows= - WT_DB::prepare("SELECT f_gedcom AS ged FROM ##families WHERE f_file=?") + WT_DB::prepare("SELECT f_gedcom AS ged FROM `##families` WHERE f_file=?") ->execute(array($this->_ged_id)) ->fetchAll(); } @@ -992,10 +992,10 @@ class stats { // used by placehierarchy googlemap module else if ($parent>0) { if ($what=='INDI') { - $join = " JOIN ##individuals ON pl_file = i_file AND pl_gid = i_id"; + $join = " JOIN `##individuals` ON pl_file = i_file AND pl_gid = i_id"; } else if ($what=='FAM') { - $join = " JOIN ##families ON pl_file = f_file AND pl_gid = f_id"; + $join = " JOIN `##families` ON pl_file = f_file AND pl_gid = f_id"; } else { $join = ""; @@ -1005,8 +1005,8 @@ class stats { .' p_place AS place,' .' COUNT(*) AS tot' .' FROM' - ." ##places" - ." JOIN ##placelinks ON pl_file=p_file AND p_id=pl_p_id" + ." `##places`" + ." JOIN `##placelinks` ON pl_file=p_file AND p_id=pl_p_id" .$join .' WHERE' ." p_id={$parent} AND" @@ -1018,10 +1018,10 @@ class stats { } else { if ($what=='INDI') { - $join = " JOIN ##individuals ON pl_file = i_file AND pl_gid = i_id"; + $join = " JOIN `##individuals` ON pl_file = i_file AND pl_gid = i_id"; } else if ($what=='FAM') { - $join = " JOIN ##families ON pl_file = f_file AND pl_gid = f_id"; + $join = " JOIN `##families` ON pl_file = f_file AND pl_gid = f_id"; } else { $join = ""; @@ -1031,8 +1031,8 @@ class stats { .' p_place AS country,' .' COUNT(*) AS tot' .' FROM' - ." ##places" - ." JOIN ##placelinks ON pl_file=p_file AND p_id=pl_p_id" + ." `##places`" + ." JOIN `##placelinks` ON pl_file=p_file AND p_id=pl_p_id" .$join .' WHERE' ." p_file={$this->_ged_id}" @@ -1046,7 +1046,7 @@ class stats { function totalPlaces() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##places WHERE p_file=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##places` WHERE p_file=?") ->execute(array($this->_ged_id)) ->fetchOne(); } @@ -1232,21 +1232,21 @@ class stats { global $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y; if ($simple) { - $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM ##dates " + $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM `##dates` " ."WHERE " ."d_file={$this->_ged_id} AND " .'d_year<>0 AND ' ."d_fact='BIRT' AND " ."d_type='@#DGREGORIAN@'"; } else if ($sex) { - $sql = "SELECT d_month, i_sex, COUNT(*) AS total FROM ##dates " - ."JOIN ##individuals ON d_file = i_file AND d_gid = i_id " + $sql = "SELECT d_month, i_sex, COUNT(*) AS total FROM `##dates` " + ."JOIN `##individuals` ON d_file = i_file AND d_gid = i_id " ."WHERE " ."d_file={$this->_ged_id} AND " ."d_fact='BIRT' AND " ."d_type='@#DGREGORIAN@'"; } else { - $sql = "SELECT d_month, COUNT(*) AS total FROM ##dates " + $sql = "SELECT d_month, COUNT(*) AS total FROM `##dates` " ."WHERE " ."d_file={$this->_ged_id} AND " ."d_fact='BIRT' AND " @@ -1290,21 +1290,21 @@ class stats { global $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y; if ($simple) { - $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM ##dates " + $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM `##dates` " ."WHERE " ."d_file={$this->_ged_id} AND " .'d_year<>0 AND ' ."d_fact='DEAT' AND " ."d_type='@#DGREGORIAN@'"; } else if ($sex) { - $sql = "SELECT d_month, i_sex, COUNT(*) AS total FROM ##dates " - ."JOIN ##individuals ON d_file = i_file AND d_gid = i_id " + $sql = "SELECT d_month, i_sex, COUNT(*) AS total FROM `##dates` " + ."JOIN `##individuals` ON d_file = i_file AND d_gid = i_id " ."WHERE " ."d_file={$this->_ged_id} AND " ."d_fact='DEAT' AND " ."d_type='@#DGREGORIAN@'"; } else { - $sql = "SELECT d_month, COUNT(*) AS total FROM ##dates " + $sql = "SELECT d_month, COUNT(*) AS total FROM `##dates` " ."WHERE " ."d_file={$this->_ged_id} AND " ."d_fact='DEAT' AND " @@ -1391,9 +1391,9 @@ class stats { .' death.d_gid AS id,' .' death.d_julianday2-birth.d_julianday1 AS age' .' FROM' - ." ##dates AS death," - ." ##dates AS birth," - ." ##individuals AS indi" + ." `##dates` AS death," + ." `##dates` AS birth," + ." `##individuals` AS indi" .' WHERE' .' indi.i_id=birth.d_gid AND' .' birth.d_gid=death.d_gid AND' @@ -1416,17 +1416,17 @@ class stats { .' death.d_julianday2-birth.d_julianday1 AS age' .' FROM' .' (SELECT d_gid, d_file, MIN(d_julianday1) AS birth_jd' - .' FROM ##date' + .' FROM `##date`' ." WHERE d_fact IN ('BIRT', 'CHR', 'BAPM', '_BRTM') AND d_julianday1>0" .' GROUP BY d_gid, d_file' .' ) AS birth' .' JOIN (' .' SELECT d_gid, d_file, MIN(d_julianday1) AS death_jd' - .' FROM ##date' + .' FROM `##date`' ." WHERE d_fact IN ('DEAT', 'BURI', 'CREM') AND d_julianday1>0" .' GROUP BY d_gid, d_file' .' ) AS death USING (d_gid, d_file)' - .' JOIN ##individuals ON (d_gid=i_id AND d_file=i_file)' + .' JOIN `##individuals` ON (d_gid=i_id AND d_file=i_file)' .' WHERE' ." i_file={$this->_ged_id} AND" .$sex_search @@ -1480,9 +1480,9 @@ class stats { .' MAX(death.d_julianday2-birth.d_julianday1) AS age,' .' death.d_gid AS deathdate' .' FROM' - ." ##dates AS death," - ." ##dates AS birth," - ." ##individuals AS indi" + ." `##dates` AS death," + ." `##dates` AS birth," + ." `##individuals` AS indi" .' WHERE' .' indi.i_id=birth.d_gid AND' .' birth.d_gid=death.d_gid AND' @@ -1552,8 +1552,8 @@ class stats { .' birth.d_gid AS id,' .' MIN(birth.d_julianday1) AS age' .' FROM' - ." ##dates AS birth," - ." ##individuals AS indi" + ." `##dates` AS birth," + ." `##individuals` AS indi" .' WHERE' .' indi.i_id=birth.d_gid AND' .' indi.i_isdead=0 AND' @@ -1612,9 +1612,9 @@ class stats { .' SELECT' .' AVG(death.d_julianday2-birth.d_julianday1) AS age' .' FROM' - ." ##dates AS death," - ." ##dates AS birth," - ." ##individuals AS indi" + ." `##dates` AS death," + ." `##dates` AS birth," + ." `##individuals` AS indi" .' WHERE' .' indi.i_id=birth.d_gid AND' .' birth.d_gid=death.d_gid AND' @@ -1654,9 +1654,9 @@ class stats { .' ROUND((death.d_year+49.1)/100) AS century,' .' i_sex AS sex' .' FROM' - ." ##dates AS death," - ." ##dates AS birth," - ." ##individuals AS indi" + ." `##dates` AS death," + ." `##dates` AS birth," + ." `##individuals` AS indi" .' WHERE' .' indi.i_id=birth.d_gid AND' .' birth.d_gid=death.d_gid AND' @@ -1736,9 +1736,9 @@ class stats { .' SELECT' .' death.d_julianday2-birth.d_julianday1 AS age' .' FROM' - ." ##dates AS death," - ." ##dates AS birth," - ." ##individuals AS indi" + ." `##dates` AS death," + ." `##dates` AS birth," + ." `##individuals` AS indi" .' WHERE' .' indi.i_id=birth.d_gid AND' .' birth.d_gid=death.d_gid AND' @@ -1821,7 +1821,7 @@ class stats { .' d_fact AS fact,' .' d_type AS type' .' FROM' - ." ##dates" + ." `##dates`" .' WHERE' ." d_file={$this->_ged_id} AND" ." d_gid<>'HEAD' AND" @@ -1919,13 +1919,13 @@ class stats { .' married.d_julianday2-birth.d_julianday1 AS age,' .' indi.i_id AS i_id' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS birth ON birth.d_file = {$this->_ged_id}" + ." `##dates` AS birth ON birth.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##dates AS married ON married.d_file = {$this->_ged_id}" + ." `##dates` AS married ON married.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}" + ." `##individuals` AS indi ON indi.i_file = {$this->_ged_id}" .' WHERE' .' birth.d_gid = indi.i_id AND' .' married.d_gid = fam.f_id AND' @@ -1946,15 +1946,15 @@ class stats { .' married.d_julianday2-birth.d_julianday1 AS age,' .' indi.i_id AS i_id' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS birth ON birth.d_file = {$this->_ged_id} AND birth.d_fact = 'BIRT'" + ." `##dates` AS birth ON birth.d_file = {$this->_ged_id} AND birth.d_fact = 'BIRT'" .' LEFT JOIN' - ." ##dates AS birth_act ON birth_act.d_file = {$this->_ged_id} AND birth_act.d_fact IN ('BIRT', 'CHR', 'BAPM', '_BRTM')" + ." `##dates` AS birth_act ON birth_act.d_file = {$this->_ged_id} AND birth_act.d_fact IN ('BIRT', 'CHR', 'BAPM', '_BRTM')" .' LEFT JOIN' - ." ##dates AS married ON married.d_file = {$this->_ged_id} AND married.d_fact = 'MARR'" + ." `##dates` AS married ON married.d_file = {$this->_ged_id} AND married.d_fact = 'MARR'" .' LEFT JOIN' - ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}" + ." `##individuals` AS indi ON indi.i_file = {$this->_ged_id}" .' WHERE' .' birth.d_gid = indi.i_id AND' .' birth_act.d_gid = indi.i_id AND' @@ -2013,11 +2013,11 @@ class stats { .' fam.f_id AS family,' .' MIN(husbdeath.d_julianday2-married.d_julianday1) AS age' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS married ON married.d_file = {$this->_ged_id}" + ." `##dates` AS married ON married.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##dates AS husbdeath ON husbdeath.d_file = {$this->_ged_id}" + ." `##dates` AS husbdeath ON husbdeath.d_file = {$this->_ged_id}" .' WHERE' ." fam.f_file = {$this->_ged_id} AND" .' husbdeath.d_gid = fam.f_husb AND' @@ -2035,11 +2035,11 @@ class stats { .' fam.f_id AS family,' .' MIN(wifedeath.d_julianday2-married.d_julianday1) AS age' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS married ON married.d_file = {$this->_ged_id}" + ." `##dates` AS married ON married.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##dates AS wifedeath ON wifedeath.d_file = {$this->_ged_id}" + ." `##dates` AS wifedeath ON wifedeath.d_file = {$this->_ged_id}" .' WHERE' ." fam.f_file = {$this->_ged_id} AND" .' wifedeath.d_gid = fam.f_wife AND' @@ -2057,11 +2057,11 @@ class stats { .' fam.f_id AS family,' .' MIN(divorced.d_julianday2-married.d_julianday1) AS age' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS married ON married.d_file = {$this->_ged_id}" + ." `##dates` AS married ON married.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##dates AS divorced ON divorced.d_file = {$this->_ged_id}" + ." `##dates` AS divorced ON divorced.d_file = {$this->_ged_id}" .' WHERE' ." fam.f_file = {$this->_ged_id} AND" .' married.d_gid = fam.f_id AND' @@ -2153,11 +2153,11 @@ class stats { .' fam.f_id AS family,' .$query1 .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS wifebirth ON wifebirth.d_file = {$this->_ged_id}" + ." `##dates` AS wifebirth ON wifebirth.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##dates AS husbbirth ON husbbirth.d_file = {$this->_ged_id}" + ." `##dates` AS husbbirth ON husbbirth.d_file = {$this->_ged_id}" .' WHERE' ." fam.f_file = {$this->_ged_id} AND" .' husbbirth.d_gid = fam.f_husb AND' @@ -2214,13 +2214,13 @@ class stats { .' parentfamily.l_to AS id,' .' childbirth.d_julianday2-birth.d_julianday1 AS age' .' FROM' - ." ##link AS parentfamily" + ." `##link` AS parentfamily" .' JOIN' - ." ##link AS childfamily ON childfamily.l_file = {$this->_ged_id}" + ." `##link` AS childfamily ON childfamily.l_file = {$this->_ged_id}" .' JOIN' - ." ##dates AS birth ON birth.d_file = {$this->_ged_id}" + ." `##dates` AS birth ON birth.d_file = {$this->_ged_id}" .' JOIN' - ." ##dates AS childbirth ON childbirth.d_file = {$this->_ged_id}" + ." `##dates` AS childbirth ON childbirth.d_file = {$this->_ged_id}" .' WHERE' .' birth.d_gid = parentfamily.l_to AND' .' childfamily.l_to = childbirth.d_gid AND' @@ -2273,7 +2273,7 @@ class stats { global $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y; if ($simple) { - $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM ##dates " + $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM `##dates` " ."WHERE " ."d_file={$this->_ged_id} AND " .'d_year<>0 AND ' @@ -2296,11 +2296,11 @@ class stats { .' married.d_month AS month,' .' indi.i_id AS indi' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS married ON married.d_file = {$this->_ged_id}" + ." `##dates` AS married ON married.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}" + ." `##individuals` AS indi ON indi.i_file = {$this->_ged_id}" .' WHERE' .' married.d_gid = fam.f_id AND' ." fam.f_file = {$this->_ged_id} AND" @@ -2310,7 +2310,7 @@ class stats { .' (indi.i_id = fam.f_husb OR indi.i_id = fam.f_wife)' .' ORDER BY fams, indi, age ASC'; } else { - $sql = "SELECT d_month, COUNT(*) AS total FROM ##dates " + $sql = "SELECT d_month, COUNT(*) AS total FROM `##dates` " ."WHERE " ."d_file={$this->_ged_id} AND " ."d_fact='MARR'"; @@ -2349,7 +2349,7 @@ class stats { global $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y; if ($simple) { - $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM ##dates " + $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM `##dates` " ."WHERE " ."d_file={$this->_ged_id} AND " .'d_year<>0 AND ' @@ -2372,11 +2372,11 @@ class stats { .' divorced.d_month AS month,' .' indi.i_id AS indi' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS divorced ON divorced.d_file = {$this->_ged_id}" + ." `##dates` AS divorced ON divorced.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}" + ." `##individuals` AS indi ON indi.i_file = {$this->_ged_id}" .' WHERE' .' divorced.d_gid = fam.f_id AND' ." fam.f_file = {$this->_ged_id} AND" @@ -2386,7 +2386,7 @@ class stats { .' (indi.i_id = fam.f_husb OR indi.i_id = fam.f_wife)' .' ORDER BY fams, indi, age ASC'; } else { - $sql = "SELECT d_month, COUNT(*) AS total FROM ##dates " + $sql = "SELECT d_month, COUNT(*) AS total FROM `##dates` " ."WHERE " ."d_file={$this->_ged_id} AND " ."d_fact IN ('DIV', 'ANUL', '_SEPR')"; @@ -2457,13 +2457,13 @@ class stats { .' ROUND((married.d_year+49.1)/100) AS century,' .' indi.i_sex AS sex' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS birth ON birth.d_file = {$this->_ged_id}" + ." `##dates` AS birth ON birth.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##dates AS married ON married.d_file = {$this->_ged_id}" + ." `##dates` AS married ON married.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}" + ." `##individuals` AS indi ON indi.i_file = {$this->_ged_id}" .' WHERE' .' birth.d_gid = indi.i_id AND' .' married.d_gid = fam.f_id AND' @@ -2562,13 +2562,13 @@ class stats { .' married.d_julianday2-birth.d_julianday1 AS age,' .' indi.i_id AS indi' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS birth ON birth.d_file = {$this->_ged_id}" + ." `##dates` AS birth ON birth.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##dates AS married ON married.d_file = {$this->_ged_id}" + ." `##dates` AS married ON married.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}" + ." `##individuals` AS indi ON indi.i_file = {$this->_ged_id}" .' WHERE' .' birth.d_gid = indi.i_id AND' .' married.d_gid = fam.f_id AND' @@ -2647,7 +2647,7 @@ class stats { function oldestFatherAge($show_years=false) {return $this->_parentsQuery('age', 'DESC', 'M', $show_years);} function totalMarriedMales() { - $rows = WT_DB::prepare("SELECT f_gedcom AS ged, f_husb AS husb FROM ##families WHERE f_file=?") + $rows = WT_DB::prepare("SELECT f_gedcom AS ged, f_husb AS husb FROM `##families` WHERE f_file=?") ->execute(array($this->_ged_id)) ->fetchAll(); $husb = array(); @@ -2661,7 +2661,7 @@ class stats { } function totalMarriedFemales() { - $rows = WT_DB::prepare("SELECT f_gedcom AS ged, f_wife AS wife FROM ##families WHERE f_file=?") + $rows = WT_DB::prepare("SELECT f_gedcom AS ged, f_wife AS wife FROM `##families` WHERE f_file=?") ->execute(array($this->_ged_id)) ->fetchAll(); $wife = array(); @@ -2684,7 +2684,7 @@ class stats { .' f_numchil AS tot,' .' f_id AS id' .' FROM' - ." ##families" + ." `##families`" .' WHERE' ." f_file={$this->_ged_id}" .' ORDER BY' @@ -2721,7 +2721,7 @@ class stats { .' f_numchil AS tot,' .' f_id AS id' .' FROM' - ." ##families" + ." `##families`" .' WHERE' ." f_file={$this->_ged_id}" .' ORDER BY' @@ -2766,13 +2766,13 @@ class stats { .' link2.l_to AS ch2,' .' child1.d_julianday2-child2.d_julianday2 AS age' .' FROM' - ." ##link AS link1" + ." `##link` AS link1" .' LEFT JOIN' - ." ##dates AS child1 ON child1.d_file = {$this->_ged_id}" + ." `##dates` AS child1 ON child1.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##dates AS child2 ON child2.d_file = {$this->_ged_id}" + ." `##dates` AS child2 ON child2.d_file = {$this->_ged_id}" .' LEFT JOIN' - ." ##link AS link2 ON link2.l_file = {$this->_ged_id}" + ." `##link` AS link2 ON link2.l_file = {$this->_ged_id}" .' WHERE' ." link1.l_file = {$this->_ged_id} AND" .' link1.l_from = link2.l_from AND' @@ -2884,7 +2884,7 @@ class stats { .' f_numchil AS tot,' .' f_id AS id' .' FROM' - ." ##families" + ." `##families`" .' WHERE' ." f_file={$this->_ged_id}" .' ORDER BY' @@ -2914,14 +2914,14 @@ class stats { } function totalChildren() { - $rows=self::_runSQL("SELECT SUM(f_numchil) AS tot FROM ##families WHERE f_file={$this->_ged_id}"); + $rows=self::_runSQL("SELECT SUM(f_numchil) AS tot FROM `##families` WHERE f_file={$this->_ged_id}"); $row=$rows[0]; return $row['tot']; } function averageChildren() { - $rows=self::_runSQL("SELECT AVG(f_numchil) AS tot FROM ##families WHERE f_file={$this->_ged_id}"); + $rows=self::_runSQL("SELECT AVG(f_numchil) AS tot FROM `##families` WHERE f_file={$this->_ged_id}"); $row=$rows[0]; return sprintf('%.2f', $row['tot']); } @@ -2936,9 +2936,9 @@ class stats { .' ROUND(AVG(f_numchil),2) AS num,' .' ROUND((married.d_year+49.1)/100) AS century' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS married ON married.d_file = {$this->_ged_id}" + ." `##dates` AS married ON married.d_file = {$this->_ged_id}" .' WHERE' .' married.d_gid = fam.f_id AND' ." fam.f_file = {$this->_ged_id} AND" @@ -2969,26 +2969,26 @@ class stats { } else { if ($sex=='M') { $sql = "SELECT num, COUNT(*) AS total FROM " - ."(SELECT count(i_sex) AS num FROM ##link " - ."LEFT OUTER JOIN ##individuals " + ."(SELECT count(i_sex) AS num FROM `##link` " + ."LEFT OUTER JOIN `##individuals` " ."ON l_from=i_id AND l_file=i_file AND i_sex='M' AND l_type='FAMC' " - ."JOIN ##families ON f_file=l_file AND f_id=l_to WHERE f_file={$this->_ged_id} GROUP BY l_to" + ."JOIN `##families` ON f_file=l_file AND f_id=l_to WHERE f_file={$this->_ged_id} GROUP BY l_to" .") boys" ." GROUP BY num ORDER BY num ASC"; } else if ($sex=='F') { $sql = "SELECT num, COUNT(*) AS total FROM " - ."(SELECT count(i_sex) AS num FROM ##link " - ."LEFT OUTER JOIN ##individuals " + ."(SELECT count(i_sex) AS num FROM `##link` " + ."LEFT OUTER JOIN `##individuals` " ."ON l_from=i_id AND l_file=i_file AND i_sex='F' AND l_type='FAMC' " - ."JOIN ##families ON f_file=l_file AND f_id=l_to WHERE f_file={$this->_ged_id} GROUP BY l_to" + ."JOIN `##families` ON f_file=l_file AND f_id=l_to WHERE f_file={$this->_ged_id} GROUP BY l_to" .") girls" ." GROUP BY num ORDER BY num ASC"; } else { - $sql = "SELECT f_numchil, COUNT(*) AS total FROM ##families "; + $sql = "SELECT f_numchil, COUNT(*) AS total FROM `##families` "; if ($year1>=0 && $year2>=0) { - $sql .= "AS fam LEFT JOIN ##dates AS married ON married.d_file = {$this->_ged_id}" + $sql .= "AS fam LEFT JOIN `##dates` AS married ON married.d_file = {$this->_ged_id}" .' WHERE' .' married.d_gid = fam.f_id AND' ." fam.f_file = {$this->_ged_id} AND" @@ -3017,7 +3017,7 @@ class stats { .' SELECT' .' COUNT(*) AS tot' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' WHERE' .' f_numchil = 0 AND' ." fam.f_file = {$this->_ged_id}"); @@ -3032,7 +3032,7 @@ class stats { .' SELECT' .' f_id AS family' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' WHERE' .' f_numchil = 0 AND' ." fam.f_file = {$this->_ged_id}"); @@ -3077,9 +3077,9 @@ class stats { .' COUNT(*) AS count,' .' ROUND((married.d_year+49.1)/100) AS century' .' FROM' - ." ##families AS fam" + ." `##families` AS fam" .' LEFT JOIN' - ." ##dates AS married ON married.d_file = {$this->_ged_id}" + ." `##dates` AS married ON married.d_file = {$this->_ged_id}" .' WHERE' .' f_numchil = 0 AND' .' married.d_gid = fam.f_id AND' @@ -3137,13 +3137,13 @@ class stats { .' COUNT(*) AS tot,' .' f_id AS id' .' FROM' - ." ##families" + ." `##families`" .' JOIN' - ." ##link AS children ON children.l_file = {$this->_ged_id}" + ." `##link` AS children ON children.l_file = {$this->_ged_id}" .' JOIN' - ." ##link AS mchildren ON mchildren.l_file = {$this->_ged_id}" + ." `##link` AS mchildren ON mchildren.l_file = {$this->_ged_id}" .' JOIN' - ." ##link AS gchildren ON gchildren.l_file = {$this->_ged_id}" + ." `##link` AS gchildren ON gchildren.l_file = {$this->_ged_id}" .' WHERE' ." f_file={$this->_ged_id} AND" ." children.l_from=f_id AND" @@ -3325,7 +3325,7 @@ class stats { } $ged_id=get_id_from_gedcom($GEDCOM); - $rows=WT_DB::prepare("SELECT n_givn, COUNT(*) AS num FROM ##name JOIN ##individuals ON (n_id=i_id AND n_file=i_file) WHERE n_file={$ged_id} AND n_type<>'_MARNM' AND n_givn NOT IN ('@P.N.', '') AND LENGTH(n_givn)>1 AND {$sex_sql} GROUP BY n_id, n_givn") + $rows=WT_DB::prepare("SELECT n_givn, COUNT(*) AS num FROM `##name` JOIN `##individuals` ON (n_id=i_id AND n_file=i_file) WHERE n_file={$ged_id} AND n_type<>'_MARNM' AND n_givn NOT IN ('@P.N.', '') AND LENGTH(n_givn)>1 AND {$sex_sql} GROUP BY n_id, n_givn") ->fetchAll(); $nameList=array(); foreach ($rows as $row) { diff --git a/includes/controllers/advancedsearch_ctrl.php b/includes/controllers/advancedsearch_ctrl.php index 3833bc261d..3f6bb17340 100644 --- a/includes/controllers/advancedsearch_ctrl.php +++ b/includes/controllers/advancedsearch_ctrl.php @@ -203,7 +203,7 @@ class AdvancedSearchController extends SearchController { if ($parts[0]=="NAME") { // The pgv_name table contains both names and soundex values if (!$namesTable) { - $sqltables.=" JOIN ##name ON (i_file=n_file AND i_id=n_id) "; + $sqltables.=" JOIN `##name` ON (i_file=n_file AND i_id=n_id) "; $namesTable = true; } switch (end($parts)) { @@ -281,7 +281,7 @@ class AdvancedSearchController extends SearchController { //-- handle dates else if (isset($parts[1]) && $parts[1]=="DATE") { if (!$datesTable) { - $sqltables.=", ##dates"; + $sqltables.=", `##dates`"; $sqlwhere .= " AND ".$prefix."_file=d_file AND ".$prefix."_id=d_gid"; $datesTable = true; } @@ -304,7 +304,7 @@ class AdvancedSearchController extends SearchController { //-- handle places else if (isset($parts[1]) && $parts[1]=="PLAC") { if (!$placesTable) { - $sqltables.=", ##places, ##placelinks"; + $sqltables.=", `##places`, `##placelinks`"; $sqlwhere .= " AND ".$prefix."_file=p_file AND p_file=pl_file AND ".$prefix."_id=pl_gid AND pl_p_id=p_id"; $placesTable = true; } @@ -332,7 +332,7 @@ class AdvancedSearchController extends SearchController { //-- handle parent/spouse names else if ($parts[0]=='FAMS') { if (!$famsTable) { - $sqltables.=", ##families as FAMS"; + $sqltables.=", `##families` as FAMS"; $sqlwhere .= " AND i_file=FAMS.f_file"; $famsTable = true; } @@ -359,7 +359,7 @@ class AdvancedSearchController extends SearchController { } else if ($parts[0]=='FAMC') { if (!$famcTable) { - $sqltables.=", ##families as FAMC"; + $sqltables.=", `##families` as FAMC"; $sqlwhere .= " AND i_file=FAMC.f_file"; $famcTable = true; } @@ -386,7 +386,7 @@ class AdvancedSearchController extends SearchController { } else if ($parts[0]=='HUSB' || $parts[0]=='WIFE') { if (!$famsTable) { - $sqltables.=", ##individuals"; + $sqltables.=", `##individuals`"; $sqlwhere .= " AND i_file=f_file"; $famsTable = true; } diff --git a/includes/controllers/remotelink_ctrl.php b/includes/controllers/remotelink_ctrl.php index 081e25c127..ea80a9dbe2 100644 --- a/includes/controllers/remotelink_ctrl.php +++ b/includes/controllers/remotelink_ctrl.php @@ -234,7 +234,7 @@ class RemoteLinkController extends BaseController { //-- check for recent additions return WT_DB::prepare( "SELECT xref". - " FROM ##change". + " FROM `##change`". " WHERE status='pending' AND gedcom_id=? AND new_gedcom LIKE CONCAT('%\n1 _DBID ', ?, '%')". " ORDER BY change_id DESC". " LIMIT 1" diff --git a/includes/functions/functions.php b/includes/functions/functions.php index c00ee4b034..a81151bead 100644 --- a/includes/functions/functions.php +++ b/includes/functions/functions.php @@ -1004,7 +1004,7 @@ function find_highlighted_object($pid, $ged_id, $indirec) { //-- find all of the media items for a person $media= - WT_DB::prepare("SELECT m_media, m_file, m_gedrec, mm_gedrec FROM ##media, ##media_mapping WHERE m_media=mm_media AND m_gedfile=mm_gedfile AND m_gedfile=? AND mm_gid=? ORDER BY mm_order") + WT_DB::prepare("SELECT m_media, m_file, m_gedrec, mm_gedrec FROM `##media`, `##media_mapping` WHERE m_media=mm_media AND m_gedfile=mm_gedfile AND m_gedfile=? AND mm_gid=? ORDER BY mm_order") ->execute(array($ged_id, $pid)) ->fetchAll(PDO::FETCH_NUM); @@ -2825,7 +2825,7 @@ function get_new_xref($type='INDI', $ged_id=WT_GED_ID, $use_cache=false) { } $num= - WT_DB::prepare("SELECT next_id FROM ##next_id WHERE record_type=? AND gedcom_id=?") + WT_DB::prepare("SELECT next_id FROM `##next_id` WHERE record_type=? AND gedcom_id=?") ->execute(array($type, $ged_id)) ->fetchOne(); @@ -2835,7 +2835,7 @@ function get_new_xref($type='INDI', $ged_id=WT_GED_ID, $use_cache=false) { if (is_null($num)) { $num = 1; - WT_DB::prepare("INSERT INTO ##next_id (gedcom_id, record_type, next_id) VALUES(?, ?, 1)") + WT_DB::prepare("INSERT INTO `##next_id` (gedcom_id, record_type, next_id) VALUES(?, ?, 1)") ->execute(array($ged_id, $type)); } @@ -2854,7 +2854,7 @@ function get_new_xref($type='INDI', $ged_id=WT_GED_ID, $use_cache=false) { $key = $prefix.$num; //-- update the next id number in the DB table - WT_DB::prepare("UPDATE ##next_id SET next_id=? WHERE record_type=? AND gedcom_id=?") + WT_DB::prepare("UPDATE `##next_id` SET next_id=? WHERE record_type=? AND gedcom_id=?") ->execute(array($num+1, $type, $ged_id)); return $key; } diff --git a/includes/functions/functions_db.php b/includes/functions/functions_db.php index 453d72c326..9ff60f5427 100644 --- a/includes/functions/functions_db.php +++ b/includes/functions/functions_db.php @@ -44,28 +44,28 @@ function get_first_xref($type, $ged_id=WT_GED_ID) { switch ($type) { case "INDI": return - WT_DB::prepare("SELECT MIN(i_id) FROM ##individuals WHERE i_file=?") + WT_DB::prepare("SELECT MIN(i_id) FROM `##individuals` WHERE i_file=?") ->execute(array($ged_id)) ->fetchOne(); break; case "FAM": return - WT_DB::prepare("SELECT MIN(f_id) FROM ##families WHERE f_file=?") + WT_DB::prepare("SELECT MIN(f_id) FROM `##families` WHERE f_file=?") ->execute(array($ged_id)) ->fetchOne(); case "SOUR": return - WT_DB::prepare("SELECT MIN(s_id) FROM ##sources WHERE s_file=?") + WT_DB::prepare("SELECT MIN(s_id) FROM `##sources` WHERE s_file=?") ->execute(array($ged_id)) ->fetchOne(); case "OBJE": return - WT_DB::prepare("SELECT MIN(m_media) FROM ##media WHERE m_gedfile=?") + WT_DB::prepare("SELECT MIN(m_media) FROM `##media` WHERE m_gedfile=?") ->execute(array($ged_id)) ->fetchOne(); default: return - WT_DB::prepare("SELECT MIN(o_id) FROM ##other WHERE o_file=? AND o_type=?") + WT_DB::prepare("SELECT MIN(o_id) FROM `##other` WHERE o_file=? AND o_type=?") ->execute(array($ged_id, $type)) ->fetchOne(); } @@ -76,28 +76,28 @@ function get_last_xref($type, $ged_id=WT_GED_ID) { switch ($type) { case "INDI": return - WT_DB::prepare("SELECT MAX(i_id) FROM ##individuals WHERE i_file=?") + WT_DB::prepare("SELECT MAX(i_id) FROM `##individuals` WHERE i_file=?") ->execute(array($ged_id)) ->fetchOne(); break; case "FAM": return - WT_DB::prepare("SELECT MAX(f_id) FROM ##families WHERE f_file=?") + WT_DB::prepare("SELECT MAX(f_id) FROM `##families` WHERE f_file=?") ->execute(array($ged_id)) ->fetchOne(); case "SOUR": return - WT_DB::prepare("SELECT MAX(s_id) FROM ##sources WHERE s_file=?") + WT_DB::prepare("SELECT MAX(s_id) FROM `##sources` WHERE s_file=?") ->execute(array($ged_id)) ->fetchOne(); case "OBJE": return - WT_DB::prepare("SELECT MAX(m_media) FROM ##media WHERE m_gedfile=?") + WT_DB::prepare("SELECT MAX(m_media) FROM `##media` WHERE m_gedfile=?") ->execute(array($ged_id)) ->fetchOne(); default: return - WT_DB::prepare("SELECT MAX(o_id) FROM ##other WHERE o_file=? AND o_type=?") + WT_DB::prepare("SELECT MAX(o_id) FROM `##other` WHERE o_file=? AND o_type=?") ->execute(array($ged_id, $type)) ->fetchOne(); } @@ -109,28 +109,28 @@ function get_next_xref($pid, $ged_id=WT_GED_ID) { switch ($type) { case "INDI": return - WT_DB::prepare("SELECT MIN(i_id) FROM ##individuals WHERE i_file=? AND i_id>?") + WT_DB::prepare("SELECT MIN(i_id) FROM `##individuals` WHERE i_file=? AND i_id>?") ->execute(array($ged_id, $pid)) ->fetchOne(); break; case "FAM": return - WT_DB::prepare("SELECT MIN(f_id) FROM ##families WHERE f_file=? AND f_id>?") + WT_DB::prepare("SELECT MIN(f_id) FROM `##families` WHERE f_file=? AND f_id>?") ->execute(array($ged_id, $pid)) ->fetchOne(); case "SOUR": return - WT_DB::prepare("SELECT MIN(s_id) FROM ##sources WHERE s_file=? AND s_id>?") + WT_DB::prepare("SELECT MIN(s_id) FROM `##sources` WHERE s_file=? AND s_id>?") ->execute(array($ged_id, $pid)) ->fetchOne(); case "OBJE": return - WT_DB::prepare("SELECT MIN(m_media) FROM ##media WHERE m_gedfile=? AND m_media>?") + WT_DB::prepare("SELECT MIN(m_media) FROM `##media` WHERE m_gedfile=? AND m_media>?") ->execute(array($ged_id, $pid)) ->fetchOne(); default: return - WT_DB::prepare("SELECT MIN(o_id) FROM ##other WHERE o_file=? AND o_type=? AND o_id>?") + WT_DB::prepare("SELECT MIN(o_id) FROM `##other` WHERE o_file=? AND o_type=? AND o_id>?") ->execute(array($ged_id, $type, $pid)) ->fetchOne(); } @@ -142,28 +142,28 @@ function get_prev_xref($pid, $ged_id=WT_GED_ID) { switch ($type) { case "INDI": return - WT_DB::prepare("SELECT MAX(i_id) FROM ##individuals WHERE i_file=? AND i_id<?") + WT_DB::prepare("SELECT MAX(i_id) FROM `##individuals` WHERE i_file=? AND i_id<?") ->execute(array($ged_id, $pid)) ->fetchOne(); break; case "FAM": return - WT_DB::prepare("SELECT MAX(f_id) FROM ##families WHERE f_file=? AND f_id<?") + WT_DB::prepare("SELECT MAX(f_id) FROM `##families` WHERE f_file=? AND f_id<?") ->execute(array($ged_id, $pid)) ->fetchOne(); case "SOUR": return - WT_DB::prepare("SELECT MAX(s_id) FROM ##sources WHERE s_file=? AND s_id<?") + WT_DB::prepare("SELECT MAX(s_id) FROM `##sources` WHERE s_file=? AND s_id<?") ->execute(array($ged_id, $pid)) ->fetchOne(); case "OBJE": return - WT_DB::prepare("SELECT MAX(m_media) FROM ##media WHERE m_gedfile=? AND m_media<?") + WT_DB::prepare("SELECT MAX(m_media) FROM `##media` WHERE m_gedfile=? AND m_media<?") ->execute(array($ged_id, $pid)) ->fetchOne(); default: return - WT_DB::prepare("SELECT MAX(o_id) FROM ##other WHERE o_file=? AND o_type=? AND o_id<?") + WT_DB::prepare("SELECT MAX(o_id) FROM `##other` WHERE o_file=? AND o_type=? AND o_id<?") ->execute(array($ged_id, $type, $pid)) ->fetchOne(); } @@ -180,14 +180,14 @@ function get_indilist_salpha($marnm, $fams, $ged_id) { // This logic relies on the database's collation rules to ensure that accented letters // and digraphs appear in the correct listing. foreach (explode(' ', i18n::$alphabet) as $letter) { - $query="SELECT COUNT(DISTINCT i_id) FROM ##individuals"; + $query="SELECT COUNT(DISTINCT i_id) FROM `##individuals`"; if ($marnm) { - $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file)"; + $query.=" JOIN `##name` ON (i_id=n_id AND i_file=n_file)"; } else { - $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')"; + $query.=" JOIN `##name` ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')"; } if ($fams) { - $query.=" JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; + $query.=" JOIN `##link` ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; } $query.=" WHERE n_file=? AND n_sort LIKE '{$letter}%' COLLATE '".i18n::$collation."'"; foreach (explode(' ', i18n::$alphabet) as $letter2) { @@ -201,14 +201,14 @@ function get_indilist_salpha($marnm, $fams, $ged_id) { // This includes "@" (unknown) and "," (none) $query= "SELECT LEFT(n_sort, 1), COUNT(DISTINCT i_id)". - " FROM ##individuals"; + " FROM `##individuals`"; if ($marnm) { - $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file)"; + $query.=" JOIN `##name` ON (i_id=n_id AND i_file=n_file)"; } else { - $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')"; + $query.=" JOIN `##name` ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')"; } if ($fams) { - $query.=" JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; + $query.=" JOIN `##link` ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; } $query.=" WHERE n_file=?"; foreach (explode(' ', i18n::$alphabet) as $letter) { @@ -245,14 +245,14 @@ function get_indilist_galpha($surn, $salpha, $marnm, $fams, $ged_id) { // This logic relies on the database's collation rules to ensure that accented letters // and digraphs appear in the correct listing. foreach (explode(' ', i18n::$alphabet) as $letter) { - $query="SELECT COUNT(DISTINCT i_id) FROM ##individuals"; + $query="SELECT COUNT(DISTINCT i_id) FROM `##individuals`"; if ($marnm) { - $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file)"; + $query.=" JOIN `##name` ON (i_id=n_id AND i_file=n_file)"; } else { - $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')"; + $query.=" JOIN `##name` ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')"; } if ($fams) { - $query.=" JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; + $query.=" JOIN `##link` ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; } $query.=" WHERE n_file=?"; if ($surn) { @@ -272,14 +272,14 @@ function get_indilist_galpha($surn, $salpha, $marnm, $fams, $ged_id) { // This includes "@" (unknown) and "," (none) $query= "SELECT LEFT(n_givn, 1), COUNT(DISTINCT i_id)". - " FROM ##individuals"; + " FROM `##individuals`"; if ($marnm) { - $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file)"; + $query.=" JOIN `##name` ON (i_id=n_id AND i_file=n_file)"; } else { - $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')"; + $query.=" JOIN `##name` ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')"; } if ($fams) { - $query.=" JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; + $query.=" JOIN `##link` ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; } $query.=" WHERE n_file=?"; if ($surn) { @@ -318,9 +318,9 @@ function get_indilist_galpha($surn, $salpha, $marnm, $fams, $ged_id) { // $ged_id - only consider individuals from this gedcom //////////////////////////////////////////////////////////////////////////////// function get_indilist_surns($surn, $salpha, $marnm, $fams, $ged_id) { - $sql="SELECT DISTINCT n_surn, n_surname, n_id FROM ##individuals JOIN ##name ON (i_id=n_id AND i_file=n_file)"; + $sql="SELECT DISTINCT n_surn, n_surname, n_id FROM `##individuals` JOIN `##name` ON (i_id=n_id AND i_file=n_file)"; if ($fams) { - $sql.=" JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; + $sql.=" JOIN `##link` ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; } $where=array("n_file={$ged_id}"); if (!$marnm) { @@ -359,7 +359,7 @@ function get_indilist_surns($surn, $salpha, $marnm, $fams, $ged_id) { // $ged_id - only consider individuals from this gedcom //////////////////////////////////////////////////////////////////////////////// function get_famlist_surns($surn, $salpha, $marnm, $ged_id) { - $sql="SELECT DISTINCT n_surn, n_surname, l_to FROM ##individuals JOIN ##name ON (i_id=n_id AND i_file=n_file) JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; + $sql="SELECT DISTINCT n_surn, n_surname, l_to FROM `##individuals` JOIN `##name` ON (i_id=n_id AND i_file=n_file) JOIN `##link` ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')"; $where=array("n_file={$ged_id}"); if (!$marnm) { $where[]="n_type!='_MARNM'"; @@ -407,9 +407,9 @@ function get_famlist_surns($surn, $salpha, $marnm, $ged_id) { // To search for names with no surnames, use $salpha="," //////////////////////////////////////////////////////////////////////////////// function get_indilist_indis($surn='', $salpha='', $galpha='', $marnm=false, $fams=false, $ged_id=null) { - $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, n_surn, n_surname, n_num FROM ##individuals JOIN ##name ON (i_id=n_id AND i_file=n_file)"; + $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, n_surn, n_surname, n_num FROM `##individuals` JOIN `##name` ON (i_id=n_id AND i_file=n_file)"; if ($fams) { - $sql.=" JOIN ##link ON (i_id=l_from AND i_file=l_file)"; + $sql.=" JOIN `##link` ON (i_id=l_from AND i_file=l_file)"; } $where=array(); if ($ged_id) { @@ -490,7 +490,7 @@ function get_famlist_fams($surn='', $salpha='', $galpha='', $marnm, $ged_id=null // with missing spouses if ($surn=='@N.N.' || $salpha=='@') { $rows= - WT_DB::prepare("SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM ##families f WHERE f_file={$ged_id} AND (f_husb='' OR f_wife='')") + WT_DB::prepare("SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM `##families` f WHERE f_file={$ged_id} AND (f_husb='' OR f_wife='')") ->execute(array($ged_id)) ->fetchAll(PDO::FETCH_ASSOC); @@ -509,7 +509,7 @@ function fetch_child_ids($parent_id, $ged_id) { static $statement=null; if (is_null($statement)) { - $statement=WT_DB::prepare("SELECT DISTINCT child.l_from AS xref FROM ##link child, ##link spouse WHERE child.l_type=? AND spouse.l_type=? AND child.l_file=spouse.l_file AND child.l_to=spouse.l_to AND spouse.l_from=? AND child.l_file=?"); + $statement=WT_DB::prepare("SELECT DISTINCT child.l_from AS xref FROM `##link` child, `##link` spouse WHERE child.l_type=? AND spouse.l_type=? AND child.l_file=spouse.l_file AND child.l_to=spouse.l_to AND spouse.l_from=? AND child.l_file=?"); } return $statement->execute(array('FAMC', 'FAMS', $parent_id, $ged_id))->fetchOneColumn(); @@ -520,31 +520,31 @@ function fetch_child_ids($parent_id, $ged_id) { //////////////////////////////////////////////////////////////////////////////// function count_linked_indi($xref, $link, $ged_id) { return - WT_DB::prepare("SELECT COUNT(*) FROM ##link, ##individuals WHERE i_file=l_file AND i_id=l_from AND l_file=? AND l_type=? AND l_to=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##link`, `##individuals` WHERE i_file=l_file AND i_id=l_from AND l_file=? AND l_type=? AND l_to=?") ->execute(array($ged_id, $link, $xref)) ->fetchOne(); } function count_linked_fam($xref, $link, $ged_id) { return - WT_DB::prepare("SELECT COUNT(*) FROM ##link, ##families WHERE f_file=l_file AND f_id=l_from AND l_file=? AND l_type=? AND l_to=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##link`, `##families` WHERE f_file=l_file AND f_id=l_from AND l_file=? AND l_type=? AND l_to=?") ->execute(array($ged_id, $link, $xref)) ->fetchOne(); } function count_linked_note($xref, $link, $ged_id) { return - WT_DB::prepare("SELECT COUNT(*) FROM ##link, ##other WHERE o_file=l_file AND o_id=l_from AND o_type=? AND l_file=? AND l_type=? AND l_to=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##link`, `##other` WHERE o_file=l_file AND o_id=l_from AND o_type=? AND l_file=? AND l_type=? AND l_to=?") ->execute(array('NOTE', $ged_id, $link, $xref)) ->fetchOne(); } function count_linked_sour($xref, $link, $ged_id) { return - WT_DB::prepare("SELECT COUNT(*) FROM ##link, ##sources WHERE s_file=l_file AND s_id=l_from AND l_file=? AND l_type=? AND l_to=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##link`, `##sources` WHERE s_file=l_file AND s_id=l_from AND l_file=? AND l_type=? AND l_to=?") ->execute(array($ged_id, $link, $xref)) ->fetchOne(); } function count_linked_obje($xref, $link, $ged_id) { return - WT_DB::prepare("SELECT COUNT(*) FROM ##link, ##media WHERE m_gedfile=l_file AND m_media=l_from AND l_file=? AND l_type=? AND l_to=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##link`, `##media` WHERE m_gedfile=l_file AND m_media=l_from AND l_file=? AND l_type=? AND l_to=?") ->execute(array($ged_id, $link, $xref)) ->fetchOne(); } @@ -555,9 +555,9 @@ function count_linked_obje($xref, $link, $ged_id) { function fetch_linked_indi($xref, $link, $ged_id) { $rows=WT_DB::prepare( "SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex". - " FROM ##individuals". - " JOIN ##link ON (i_file=l_file AND i_id=l_from)". - " LEFT JOIN ##name ON (i_file=n_file AND i_id=n_id AND n_num=0)". + " FROM `##individuals`". + " JOIN `##link` ON (i_file=l_file AND i_id=l_from)". + " LEFT JOIN `##name` ON (i_file=n_file AND i_id=n_id AND n_num=0)". " WHERE i_file=? AND l_type=? AND l_to=?". " ORDER BY n_sort" )->execute(array($ged_id, $link, $xref))->fetchAll(PDO::FETCH_ASSOC); @@ -571,9 +571,9 @@ function fetch_linked_indi($xref, $link, $ged_id) { function fetch_linked_fam($xref, $link, $ged_id) { $rows=WT_DB::prepare( "SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil". - " FROM ##families". - " JOIN ##link ON (f_file=l_file AND f_id=l_from)". - " LEFT JOIN ##name ON (f_file=n_file AND f_id=n_id AND n_num=0)". + " FROM `##families`". + " JOIN `##link` ON (f_file=l_file AND f_id=l_from)". + " LEFT JOIN `##name` ON (f_file=n_file AND f_id=n_id AND n_num=0)". " WHERE f_file=? AND l_type=? AND l_to=?". " ORDER BY n_sort" )->execute(array($ged_id, $link, $xref))->fetchAll(PDO::FETCH_ASSOC); @@ -587,9 +587,9 @@ function fetch_linked_fam($xref, $link, $ged_id) { function fetch_linked_note($xref, $link, $ged_id) { $rows=WT_DB::prepare( "SELECT 'NOTE' AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec". - " FROM ##other". - " JOIN ##link ON (o_file=l_file AND o_id=l_from)". - " LEFT JOIN ##name ON (o_file=n_file AND o_id=n_id AND n_num=0)". + " FROM `##other`". + " JOIN `##link` ON (o_file=l_file AND o_id=l_from)". + " LEFT JOIN `##name` ON (o_file=n_file AND o_id=n_id AND n_num=0)". " WHERE o_file=? AND o_type='NOTE' AND l_type=? AND l_to=?". " ORDER BY n_sort" )->execute(array($ged_id, $link, $xref))->fetchAll(PDO::FETCH_ASSOC); @@ -603,9 +603,9 @@ function fetch_linked_note($xref, $link, $ged_id) { function fetch_linked_sour($xref, $link, $ged_id) { $rows=WT_DB::prepare( "SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec". - " FROM ##sources". - " JOIN ##link ON (s_file=l_file AND s_id=l_from)". - " LEFT JOIN ##name ON (s_file=n_file AND s_id=n_id AND n_num=0)". + " FROM `##sources`". + " JOIN `##link` ON (s_file=l_file AND s_id=l_from)". + " LEFT JOIN `##name` ON (s_file=n_file AND s_id=n_id AND n_num=0)". " WHERE s_file=? AND l_type=? AND l_to=?". " ORDER BY n_sort" )->execute(array($ged_id, $link, $xref))->fetchAll(PDO::FETCH_ASSOC); @@ -619,9 +619,9 @@ function fetch_linked_sour($xref, $link, $ged_id) { function fetch_linked_obje($xref, $link, $ged_id) { $rows=WT_DB::prepare( "SELECT 'OBJE' AS type, m_media AS xref, m_gedfile AS ged_id, m_gedrec AS gedrec, m_titl, m_file". - " FROM ##media". - " JOIN ##link ON (m_gedfile=l_file AND m_media=l_from)". - " LEFT JOIN ##name ON (m_gedfile=n_file AND m_media=n_id AND n_num=0)". + " FROM `##media`". + " JOIN `##link` ON (m_gedfile=l_file AND m_media=l_from)". + " LEFT JOIN `##name` ON (m_gedfile=n_file AND m_media=n_id AND n_num=0)". " WHERE m_gedfile=? AND l_type=? AND l_to=?". " ORDER BY n_sort" )->execute(array($ged_id, $link, $xref))->fetchAll(PDO::FETCH_ASSOC); @@ -639,7 +639,7 @@ function fetch_linked_obje($xref, $link, $ged_id) { //////////////////////////////////////////////////////////////////////////////// function fetch_all_links($xref, $ged_id) { return - WT_DB::prepare("SELECT l_from FROM ##link WHERE l_file=? AND l_to=?") + WT_DB::prepare("SELECT l_from FROM `##link` WHERE l_file=? AND l_to=?") ->execute(array($ged_id, $xref)) ->fetchOneColumn(); } @@ -656,7 +656,7 @@ function fetch_person_record($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( "SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex ". - "FROM ##individuals WHERE i_id=? AND i_file=?" + "FROM `##individuals` WHERE i_id=? AND i_file=?" ); } return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC); @@ -667,7 +667,7 @@ function fetch_family_record($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( "SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil ". - "FROM ##families WHERE f_id=? AND f_file=?" + "FROM `##families` WHERE f_id=? AND f_file=?" ); } return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC); @@ -678,7 +678,7 @@ function fetch_source_record($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( "SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec ". - "FROM ##sources WHERE s_id=? AND s_file=?" + "FROM `##sources` WHERE s_id=? AND s_file=?" ); } return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC); @@ -693,7 +693,7 @@ function fetch_media_record($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( "SELECT 'OBJE' AS type, m_media AS xref, m_gedfile AS ged_id, m_gedrec AS gedrec, m_titl, m_file ". - "FROM ##media WHERE m_media=? AND m_gedfile=?" + "FROM `##media` WHERE m_media=? AND m_gedfile=?" ); } return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC); @@ -704,7 +704,7 @@ function fetch_other_record($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( "SELECT o_type AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec ". - "FROM ##other WHERE o_id=? AND o_file=?" + "FROM `##other` WHERE o_id=? AND o_file=?" ); } return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC); @@ -756,7 +756,7 @@ function find_family_record($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( - "SELECT f_gedcom FROM ##families WHERE f_id=? AND f_file=?" + "SELECT f_gedcom FROM `##families` WHERE f_id=? AND f_file=?" ); } return $statement->execute(array($xref, $ged_id))->fetchOne(); @@ -774,7 +774,7 @@ function find_person_record($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( - "SELECT i_gedcom FROM ##individuals WHERE i_id=? AND i_file=?" + "SELECT i_gedcom FROM `##individuals` WHERE i_id=? AND i_file=?" ); } return $statement->execute(array($xref, $ged_id))->fetchOne(); @@ -792,7 +792,7 @@ function find_source_record($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( - "SELECT s_gedcom FROM ##sources WHERE s_id=? AND s_file=?" + "SELECT s_gedcom FROM `##sources` WHERE s_id=? AND s_file=?" ); } return $statement->execute(array($xref, $ged_id))->fetchOne(); @@ -808,7 +808,7 @@ function find_other_record($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( - "SELECT o_gedcom FROM ##other WHERE o_id=? AND o_file=?" + "SELECT o_gedcom FROM `##other` WHERE o_id=? AND o_file=?" ); } return $statement->execute(array($xref, $ged_id))->fetchOne(); @@ -823,7 +823,7 @@ function find_media_record($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( - "SELECT m_gedrec FROM ##media WHERE m_media=? AND m_gedfile=?" + "SELECT m_gedrec FROM `##media` WHERE m_media=? AND m_gedfile=?" ); } return $statement->execute(array($xref, $ged_id))->fetchOne(); @@ -835,11 +835,11 @@ function find_gedcom_record($xref, $ged_id, $pending=false) { if (is_null($statement)) { $statement=WT_DB::prepare( - "SELECT i_gedcom FROM ##individuals WHERE i_id =? AND i_file =? UNION ALL ". - "SELECT f_gedcom FROM ##families WHERE f_id =? AND f_file =? UNION ALL ". - "SELECT s_gedcom FROM ##sources WHERE s_id =? AND s_file =? UNION ALL ". - "SELECT m_gedrec FROM ##media WHERE m_media=? AND m_gedfile=? UNION ALL ". - "SELECT o_gedcom FROM ##other WHERE o_id =? AND o_file =?" + "SELECT i_gedcom FROM `##individuals` WHERE i_id =? AND i_file =? UNION ALL ". + "SELECT f_gedcom FROM `##families` WHERE f_id =? AND f_file =? UNION ALL ". + "SELECT s_gedcom FROM `##sources` WHERE s_id =? AND s_file =? UNION ALL ". + "SELECT m_gedrec FROM `##media` WHERE m_media=? AND m_gedfile=? UNION ALL ". + "SELECT o_gedcom FROM `##other` WHERE o_id =? AND o_file =?" ); } @@ -870,7 +870,7 @@ function find_updated_record($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( - "SELECT new_gedcom FROM ##change WHERE gedcom_id=? AND xref=? AND status='pending' ". + "SELECT new_gedcom FROM `##change` WHERE gedcom_id=? AND xref=? AND status='pending' ". "ORDER BY change_id DESC LIMIT 1" ); } @@ -887,11 +887,11 @@ function gedcom_record_type($xref, $ged_id) { if (is_null($statement)) { $statement=WT_DB::prepare( - "SELECT 'INDI' FROM ##individuals WHERE i_id =? AND i_file =? UNION ALL ". - "SELECT 'FAM' FROM ##families WHERE f_id =? AND f_file =? UNION ALL ". - "SELECT 'SOUR' FROM ##sources WHERE s_id =? AND s_file =? UNION ALL ". - "SELECT 'OBJE' FROM ##media WHERE m_media=? AND m_gedfile=? UNION ALL ". - "SELECT o_type FROM ##other WHERE o_id =? AND o_file =?" + "SELECT 'INDI' FROM `##individuals` WHERE i_id =? AND i_file =? UNION ALL ". + "SELECT 'FAM' FROM `##families` WHERE f_id =? AND f_file =? UNION ALL ". + "SELECT 'SOUR' FROM `##sources` WHERE s_id =? AND s_file =? UNION ALL ". + "SELECT 'OBJE' FROM `##media` WHERE m_media=? AND m_gedfile=? UNION ALL ". + "SELECT o_type FROM `##other` WHERE o_id =? AND o_file =?" ); } @@ -908,7 +908,7 @@ function exists_pending_change($user_id=WT_USER_ID, $ged_id=WT_GED_ID) { return WT_DB::prepare( "SELECT 1". - " FROM ##change". + " FROM `##change`". " WHERE status='pending' AND gedcom_id=?" )->execute(array($ged_id))->fetchOne(); } else { @@ -929,14 +929,14 @@ function exists_pending_change($user_id=WT_USER_ID, $ged_id=WT_GED_ID) { */ function update_isdead($xref, $ged_id, $isdead) { $isdead=$isdead ? 1 : 0; // DB uses int, not bool - WT_DB::prepare("UPDATE ##individuals SET i_isdead=? WHERE i_id=? AND i_file=?")->execute(array($isdead, $xref, $ged_id)); + WT_DB::prepare("UPDATE `##individuals` SET i_isdead=? WHERE i_id=? AND i_file=?")->execute(array($isdead, $xref, $ged_id)); return $isdead; } // Reset the i_isdead status for individuals // This is necessary when we change the MAX_ALIVE_YEARS value function reset_isdead($ged_id=WT_GED_ID) { - WT_DB::prepare("UPDATE ##individuals SET i_isdead=-1 WHERE i_file=?")->execute(array($ged_id)); + WT_DB::prepare("UPDATE `##individuals` SET i_isdead=-1 WHERE i_file=?")->execute(array($ged_id)); } /** @@ -948,7 +948,7 @@ function reset_isdead($ged_id=WT_GED_ID) { */ function get_source_list($ged_id) { $rows= - WT_DB::prepare("SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec FROM ##sources s WHERE s_file=?") + WT_DB::prepare("SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec FROM `##sources` s WHERE s_file=?") ->execute(array($ged_id)) ->fetchAll(PDO::FETCH_ASSOC); @@ -964,7 +964,7 @@ function get_source_list($ged_id) { // $ged_id - the gedcom to search function get_repo_list($ged_id) { $rows= - WT_DB::prepare("SELECT 'REPO' AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec FROM ##other WHERE o_type='REPO' AND o_file=?") + WT_DB::prepare("SELECT 'REPO' AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec FROM `##other` WHERE o_type='REPO' AND o_file=?") ->execute(array($ged_id)) ->fetchAll(PDO::FETCH_ASSOC); @@ -979,7 +979,7 @@ function get_repo_list($ged_id) { //-- get the shared note list from the datastore function get_note_list($ged_id) { $rows= - WT_DB::prepare("SELECT 'NOTE' AS type, o_id AS xref, {$ged_id} AS ged_id, o_gedcom AS gedrec FROM ##other WHERE o_type=? AND o_file=?") + WT_DB::prepare("SELECT 'NOTE' AS type, o_id AS xref, {$ged_id} AS ged_id, o_gedcom AS gedrec FROM `##other` WHERE o_type=? AND o_file=?") ->execute(array('NOTE', $ged_id)) ->fetchAll(PDO::FETCH_ASSOC); @@ -994,7 +994,7 @@ function get_note_list($ged_id) { // Search for INDIs using custom SQL generated by the report engine function search_indis_custom($join, $where, $order) { - $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM ##individuals ".implode(' ', $join).' WHERE '.implode(' AND ', $where); + $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM `##individuals` ".implode(' ', $join).' WHERE '.implode(' AND ', $where); if ($order) { $sql.=' ORDER BY '.implode(' ', $order); } @@ -1021,7 +1021,7 @@ function search_indis_custom($join, $where, $order) { // Search for FAMs using custom SQL generated by the report engine function search_fams_custom($join, $where, $order) { - $sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM ##families ".implode(' ', $join).' WHERE '.implode(' AND ', $where); + $sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM `##families` ".implode(' ', $join).' WHERE '.implode(' AND ', $where); if ($order) { $sql.=' ORDER BY '.implode(' ', $order); } @@ -1069,7 +1069,7 @@ function search_indis($query, $geds, $match, $skip) { $querysql[]="i_gedcom LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."'"; } - $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM ##individuals WHERE (".implode(" {$match} ", $querysql).') AND i_file IN ('.implode(',', $geds).')'; + $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM `##individuals` WHERE (".implode(" {$match} ", $querysql).') AND i_file IN ('.implode(',', $geds).')'; // Group results by gedcom, to minimise switching between privacy files $sql.=' ORDER BY ged_id'; @@ -1122,7 +1122,7 @@ function search_indis_names($query, $geds, $match) { foreach ($query as $q) { $querysql[]="n_full LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."'"; } - $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, n_num FROM ##individuals JOIN ##name ON i_id=n_id AND i_file=n_file WHERE (".implode(" {$match} ", $querysql).') AND i_file IN ('.implode(',', $geds).')'; + $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, n_num FROM `##individuals` JOIN `##name` ON i_id=n_id AND i_file=n_file WHERE (".implode(" {$match} ", $querysql).') AND i_file IN ('.implode(',', $geds).')'; // Group results by gedcom, to minimise switching between privacy files $sql.=' ORDER BY ged_id'; @@ -1161,13 +1161,13 @@ function search_indis_names($query, $geds, $match) { // $lastname, $firstname, $place - search terms // $geds - array of gedcoms to search function search_indis_soundex($soundex, $lastname, $firstname, $place, $geds) { - $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM ##individuals"; + $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM `##individuals`"; if ($place) { - $sql.=" JOIN ##placelinks ON (pl_file=i_file AND pl_gid=i_id)"; - $sql.=" JOIN ##places ON (p_file=pl_file AND pl_p_id=p_id)"; + $sql.=" JOIN `##placelinks` ON (pl_file=i_file AND pl_gid=i_id)"; + $sql.=" JOIN `##places` ON (p_file=pl_file AND pl_p_id=p_id)"; } if ($firstname || $lastname) { - $sql.=" JOIN ##name ON (i_file=n_file AND i_id=n_id)"; + $sql.=" JOIN `##name` ON (i_file=n_file AND i_id=n_id)"; } $sql.=' WHERE i_file IN ('.implode(',', $geds).')'; switch ($soundex) { @@ -1236,7 +1236,7 @@ function search_indis_soundex($soundex, $lastname, $firstname, $place, $geds) { * @param int $jd, leave empty to include all */ function get_recent_changes($jd=0, $allgeds=false) { - $sql="SELECT d_gid FROM ##dates WHERE d_fact='CHAN' AND d_julianday1>=? AND d_gid NOT LIKE ?"; + $sql="SELECT d_gid FROM `##dates` WHERE d_fact='CHAN' AND d_julianday1>=? AND d_gid NOT LIKE ?"; $vars=array($jd, '%:%'); if (!$allgeds) { $sql.=" AND d_file=?"; @@ -1249,7 +1249,7 @@ function get_recent_changes($jd=0, $allgeds=false) { // Seach for individuals with events on a given day function search_indis_dates($day, $month, $year, $facts) { - $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM ##individuals JOIN ##dates ON i_id=d_gid AND i_file=d_file WHERE i_file=?"; + $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM `##individuals` JOIN `##dates` ON i_id=d_gid AND i_file=d_file WHERE i_file=?"; $vars=array(WT_GED_ID); if ($day) { $sql.=" AND d_day=?"; @@ -1287,7 +1287,7 @@ function search_indis_dates($day, $month, $year, $facts) { // Seach for individuals with events in a given date range function search_indis_daterange($start, $end, $facts) { - $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM ##individuals JOIN ##dates ON i_id=d_gid AND i_file=d_file WHERE i_file=? AND d_julianday1 BETWEEN ? AND ?"; + $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM `##individuals` JOIN `##dates` ON i_id=d_gid AND i_file=d_file WHERE i_file=? AND d_julianday1 BETWEEN ? AND ?"; $vars=array(WT_GED_ID, $start, $end); if ($facts) { @@ -1341,7 +1341,7 @@ function search_fams($query, $geds, $match, $skip) { $querysql[]="f_gedcom LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."'"; } - $sql="SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM ##families WHERE (".implode(" {$match} ", $querysql).') AND f_file IN ('.implode(',', $geds).')'; + $sql="SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM `##families` WHERE (".implode(" {$match} ", $querysql).') AND f_file IN ('.implode(',', $geds).')'; // Group results by gedcom, to minimise switching between privacy files $sql.=' ORDER BY ged_id'; @@ -1395,7 +1395,7 @@ function search_fams_names($query, $geds, $match) { $querysql[]="(husb.n_full LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."' OR wife.n_full LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."')"; } - $sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM ##families LEFT OUTER JOIN ##name husb ON f_husb=husb.n_id AND f_file=husb.n_file LEFT OUTER JOIN ##name wife ON f_wife=wife.n_id AND f_file=wife.n_file WHERE (".implode(" {$match} ", $querysql).') AND f_file IN ('.implode(',', $geds).')'; + $sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM `##families` LEFT OUTER JOIN `##name` husb ON f_husb=husb.n_id AND f_file=husb.n_file LEFT OUTER JOIN `##name` wife ON f_wife=wife.n_id AND f_file=wife.n_file WHERE (".implode(" {$match} ", $querysql).') AND f_file IN ('.implode(',', $geds).')'; // Group results by gedcom, to minimise switching between privacy files $sql.=' ORDER BY ged_id'; @@ -1446,7 +1446,7 @@ function search_sources($query, $geds, $match, $skip) { $querysql[]="s_gedcom LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."'"; } - $sql="SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec FROM ##sources WHERE (".implode(" {$match} ", $querysql).') AND s_file IN ('.implode(',', $geds).')'; + $sql="SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec FROM `##sources` WHERE (".implode(" {$match} ", $querysql).') AND s_file IN ('.implode(',', $geds).')'; // Group results by gedcom, to minimise switching between privacy files $sql.=' ORDER BY ged_id'; @@ -1505,7 +1505,7 @@ function search_notes($query, $geds, $match, $skip) { $querysql[]="o_gedcom LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."'"; } - $sql="SELECT 'NOTE' AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec FROM ##other WHERE (".implode(" {$match} ", $querysql).") AND o_type='NOTE' AND o_file IN (".implode(',', $geds).')'; + $sql="SELECT 'NOTE' AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec FROM `##other` WHERE (".implode(" {$match} ", $querysql).") AND o_type='NOTE' AND o_file IN (".implode(',', $geds).')'; // Group results by gedcom, to minimise switching between privacy files $sql.=' ORDER BY ged_id'; @@ -1551,7 +1551,7 @@ function get_place_parent_id($parent, $level) { static $statement=null; if (is_null($statement)) { - $statement=WT_DB::prepare("SELECT p_id FROM ##places WHERE p_level=? AND p_parent_id=? AND p_place LIKE ? AND p_file=?"); + $statement=WT_DB::prepare("SELECT p_id FROM `##places` WHERE p_level=? AND p_parent_id=? AND p_place LIKE ? AND p_file=?"); } $parent_id=0; @@ -1575,12 +1575,12 @@ function get_place_list($parent, $level) { // --- find all of the place in the file if ($level==0) { return - WT_DB::prepare("SELECT p_place FROM ##places WHERE p_level=? AND p_file=? ORDER BY p_place") + WT_DB::prepare("SELECT p_place FROM `##places` WHERE p_level=? AND p_file=? ORDER BY p_place") ->execute(array(0, WT_GED_ID)) ->fetchOneColumn(); } else { return - WT_DB::prepare("SELECT p_place FROM ##places WHERE p_level=? AND p_parent_id=? AND p_file=? ORDER BY p_place") + WT_DB::prepare("SELECT p_place FROM `##places` WHERE p_level=? AND p_parent_id=? AND p_file=? ORDER BY p_place") ->execute(array($level, get_place_parent_id($parent, $level), WT_GED_ID)) ->fetchOneColumn(); } @@ -1597,13 +1597,13 @@ function get_place_positions($parent, $level='') { if ($level!=='') { return - WT_DB::prepare("SELECT DISTINCT pl_gid FROM ##placelinks WHERE pl_p_id=? AND pl_file=?") + WT_DB::prepare("SELECT DISTINCT pl_gid FROM `##placelinks` WHERE pl_p_id=? AND pl_file=?") ->execute(array(get_place_parent_id($parent, $level), WT_GED_ID)) ->fetchOneColumn(); } else { //-- we don't know the level so get the any matching place return - WT_DB::prepare("SELECT DISTINCT pl_gid FROM ##placelinks, ##places WHERE p_place LIKE ? AND p_file=pl_file AND p_id=pl_p_id AND p_file=?") + WT_DB::prepare("SELECT DISTINCT pl_gid FROM `##placelinks`, `##places` WHERE p_place LIKE ? AND p_file=pl_file AND p_id=pl_p_id AND p_file=?") ->execute(array($parent, WT_GED_ID)) ->fetchOneColumn(); } @@ -1612,7 +1612,7 @@ function get_place_positions($parent, $level='') { //-- find all of the places function find_place_list($place) { $rows= - WT_DB::prepare("SELECT p_id, p_place, p_parent_id FROM ##places WHERE p_file=? ORDER BY p_parent_id, p_id") + WT_DB::prepare("SELECT p_id, p_place, p_parent_id FROM `##places` WHERE p_file=? ORDER BY p_parent_id, p_id") ->execute(array(WT_GED_ID)) ->fetchAll(); @@ -1642,7 +1642,7 @@ function find_place_list($place) { //-- function to find the gedcom id for the given rin function find_rin_id($rin) { $xref= - WT_DB::prepare("SELECT i_id FROM ##individuals WHERE i_rin=? AND i_file=?") + WT_DB::prepare("SELECT i_id FROM `##individuals` WHERE i_rin=? AND i_file=?") ->execute(array($rin, WT_GED_ID)) ->fetchOne(); @@ -1658,30 +1658,30 @@ function delete_gedcom($ged_id) { $ged=get_gedcom_from_id($ged_id); // Don't delete the logs. - WT_DB::prepare("UPDATE ##log SET gedcom_id=NULL WHERE gedcom_id =?")->execute(array($ged_id)); + WT_DB::prepare("UPDATE `##log` SET gedcom_id=NULL WHERE gedcom_id =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE ##block_setting FROM ##block_setting JOIN ##block USING (block_id) WHERE gedcom_id=?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##block WHERE gedcom_id =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##news WHERE n_username=?")->execute(array($ged )); - WT_DB::prepare("DELETE FROM ##dates WHERE d_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##families WHERE f_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##favorites WHERE fv_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##user_gedcom_setting WHERE gedcom_id =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##gedcom_setting WHERE gedcom_id =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##individuals WHERE i_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##link WHERE l_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##media WHERE m_gedfile =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##media_mapping WHERE mm_gedfile=?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##module_privacy WHERE gedcom_id =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##name WHERE n_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##next_id WHERE gedcom_id =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##other WHERE o_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##placelinks WHERE pl_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##places WHERE p_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##sources WHERE s_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##hit_counter WHERE gedcom_id =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##change WHERE gedcom_id =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##gedcom WHERE gedcom_id =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE `##block_setting` FROM `##block_setting` JOIN `##block` USING (block_id) WHERE gedcom_id=?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##block` WHERE gedcom_id =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##news` WHERE n_username=?")->execute(array($ged )); + WT_DB::prepare("DELETE FROM `##dates` WHERE d_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##families` WHERE f_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##favorites` WHERE fv_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##user_gedcom_setting` WHERE gedcom_id =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##gedcom_setting` WHERE gedcom_id =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##individuals` WHERE i_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##link` WHERE l_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##media` WHERE m_gedfile =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##media_mapping` WHERE mm_gedfile=?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##module_privacy` WHERE gedcom_id =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##name` WHERE n_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##next_id` WHERE gedcom_id =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##other` WHERE o_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##placelinks` WHERE pl_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##places` WHERE p_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##sources` WHERE s_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##hit_counter` WHERE gedcom_id =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##change` WHERE gedcom_id =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##gedcom` WHERE gedcom_id =?")->execute(array($ged_id)); if (get_site_setting('DEFAULT_GEDCOM')==$ged) { set_site_setting('DEFAULT_GEDCOM', ''); @@ -1699,7 +1699,7 @@ function get_top_surnames($ged_id, $min, $max) { // Use n_surn, rather than n_surname, as it is used to generate url's for // the inid-list, etc. return - WT_DB::prepareLimit("SELECT n_surn, COUNT(n_surn) FROM ##name WHERE n_file=? AND n_type!=? AND n_surn NOT IN (?, ?, ?, ?) GROUP BY n_surn HAVING COUNT(n_surn)>=".$min." ORDER BY 2 DESC", $max) + WT_DB::prepareLimit("SELECT n_surn, COUNT(n_surn) FROM `##name` WHERE n_file=? AND n_type!=? AND n_surn NOT IN (?, ?, ?, ?) GROUP BY n_surn HAVING COUNT(n_surn)>=".$min." ORDER BY 2 DESC", $max) ->execute(array($ged_id, '_MARNM', '@N.N.', '', '?', 'UNKNOWN')) ->fetchAssoc(); } @@ -1732,7 +1732,7 @@ function get_next_id($table, $field) { function get_server_list($ged_id=WT_GED_ID){ $sitelist = array(); - $rows=WT_DB::prepare("SELECT s_id, s_name, s_gedcom, s_file FROM ##sources WHERE s_file=? AND s_dbid=? ORDER BY s_name") + $rows=WT_DB::prepare("SELECT s_id, s_name, s_gedcom, s_file FROM `##sources` WHERE s_file=? AND s_dbid=? ORDER BY s_name") ->execute(array($ged_id, 'Y')) ->fetchAll(); foreach ($rows as $row) { @@ -1800,7 +1800,7 @@ function delete_fact($linenum, $pid, $gedrec) { */ function get_remote_id($rfn) { return - WT_DB::prepare("SELECT r_gid FROM ##remotelinks WHERE r_linkid=? AND r_file=?") + WT_DB::prepare("SELECT r_gid FROM `##remotelinks` WHERE r_linkid=? AND r_file=?") ->execute(array($rfn, WT_GED_ID)) ->fetchOne(); } @@ -1941,8 +1941,8 @@ function get_anniversary_events($jd, $facts='', $ged_id=WT_GED_ID) { $where.=" AND d_file=".$ged_id; // Now fetch these anniversaries - $ind_sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, d_type, d_day, d_month, d_year, d_fact, d_type FROM ##dates, ##individuals {$where} AND d_gid=i_id AND d_file=i_file ORDER BY d_day ASC, d_year DESC"; - $fam_sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil, d_type, d_day, d_month, d_year, d_fact, d_type FROM ##dates, ##families {$where} AND d_gid=f_id AND d_file=f_file ORDER BY d_day ASC, d_year DESC"; + $ind_sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, d_type, d_day, d_month, d_year, d_fact, d_type FROM `##dates`, `##individuals` {$where} AND d_gid=i_id AND d_file=i_file ORDER BY d_day ASC, d_year DESC"; + $fam_sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil, d_type, d_day, d_month, d_year, d_fact, d_type FROM `##dates`, `##families` {$where} AND d_gid=f_id AND d_file=f_file ORDER BY d_day ASC, d_year DESC"; foreach (array($ind_sql, $fam_sql) as $sql) { $rows=WT_DB::prepare($sql)->fetchAll(PDO::FETCH_ASSOC); foreach ($rows as $row) { @@ -2027,8 +2027,8 @@ function get_calendar_events($jd1, $jd2, $facts='', $ged_id=WT_GED_ID) { $where.=" AND d_file=".$ged_id; // Now fetch these events - $ind_sql="SELECT d_gid, i_gedcom, 'INDI', d_type, d_day, d_month, d_year, d_fact, d_type FROM ##dates, ##individuals {$where} AND d_gid=i_id AND d_file=i_file ORDER BY d_julianday1"; - $fam_sql="SELECT d_gid, f_gedcom, 'FAM', d_type, d_day, d_month, d_year, d_fact, d_type FROM ##dates, ##families {$where} AND d_gid=f_id AND d_file=f_file ORDER BY d_julianday1"; + $ind_sql="SELECT d_gid, i_gedcom, 'INDI', d_type, d_day, d_month, d_year, d_fact, d_type FROM `##dates`, `##individuals` {$where} AND d_gid=i_id AND d_file=i_file ORDER BY d_julianday1"; + $fam_sql="SELECT d_gid, f_gedcom, 'FAM', d_type, d_day, d_month, d_year, d_fact, d_type FROM `##dates`, `##families` {$where} AND d_gid=f_id AND d_file=f_file ORDER BY d_julianday1"; foreach (array($ind_sql, $fam_sql) as $sql) { $rows=WT_DB::prepare($sql)->fetchAll(PDO::FETCH_NUM); foreach ($rows as $row) { @@ -2101,7 +2101,7 @@ function get_events_list($jd1, $jd2, $events='') { //////////////////////////////////////////////////////////////////////////////// function is_media_used_in_other_gedcom($file_name, $ged_id) { return - (bool)WT_DB::prepare("SELECT COUNT(*) FROM ##media WHERE m_file LIKE ? AND m_gedfile<>?") + (bool)WT_DB::prepare("SELECT COUNT(*) FROM `##media` WHERE m_file LIKE ? AND m_gedfile<>?") ->execute(array("%{$file_name}", $ged_id)) ->fetchOne(); } @@ -2115,16 +2115,16 @@ function is_media_used_in_other_gedcom($file_name, $ged_id) { function get_site_setting($setting_name, $default_value=null) { return WT_DB::prepare( - "SELECT setting_value FROM ##site_setting WHERE setting_name=?" + "SELECT setting_value FROM `##site_setting` WHERE setting_name=?" )->execute(array($setting_name))->fetchOne($default_value); } function set_site_setting($setting_name, $setting_value) { if (is_null($setting_value)) { - WT_DB::prepare("DELETE FROM ##site_setting WHERE setting_name=?") + WT_DB::prepare("DELETE FROM `##site_setting` WHERE setting_name=?") ->execute(array($setting_name)); } else { - WT_DB::prepare("REPLACE INTO ##site_setting (setting_name, setting_value) VALUES (?, ?)") + WT_DB::prepare("REPLACE INTO `##site_setting` (setting_name, setting_value) VALUES (?, ?)") ->execute(array($setting_name, $setting_value)); } } @@ -2135,7 +2135,7 @@ function set_site_setting($setting_name, $setting_value) { function get_all_gedcoms() { return - WT_DB::prepare("SELECT gedcom_id, gedcom_name FROM ##gedcom") + WT_DB::prepare("SELECT gedcom_id, gedcom_name FROM `##gedcom`") ->fetchAssoc(); } @@ -2143,8 +2143,8 @@ function get_gedcom_titles() { return WT_DB::prepare( "SELECT g.gedcom_id, g.gedcom_name, COALESCE(gs.setting_value, g.gedcom_name) AS gedcom_title". - " FROM ##gedcom g". - " LEFT JOIN ##gedcom_setting gs ON (g.gedcom_id=gs.gedcom_id AND gs.setting_name=?)". + " FROM `##gedcom` g". + " LEFT JOIN `##gedcom_setting` gs ON (g.gedcom_id=gs.gedcom_id AND gs.setting_name=?)". " ORDER BY 3" ) ->execute(array('title')) @@ -2158,7 +2158,7 @@ function get_gedcom_from_id($ged_id) { } return - WT_DB::prepare("SELECT gedcom_name FROM ##gedcom WHERE gedcom_id=?") + WT_DB::prepare("SELECT gedcom_name FROM `##gedcom` WHERE gedcom_id=?") ->execute(array($ged_id)) ->fetchOne(); } @@ -2173,7 +2173,7 @@ function get_id_from_gedcom($ged_name, $create=false) { if ($create) { try { - WT_DB::prepare("INSERT INTO ##gedcom (gedcom_name, import_gedcom, import_offset) VALUES (?, '', 0)") + WT_DB::prepare("INSERT INTO `##gedcom` (gedcom_name, import_gedcom, import_offset) VALUES (?, '', 0)") ->execute(array($ged_name)); $ged_id=WT_DB::getInstance()->lastInsertId(); require WT_ROOT.'includes/set_gedcom_defaults.php'; @@ -2184,7 +2184,7 @@ function get_id_from_gedcom($ged_name, $create=false) { } return - WT_DB::prepare("SELECT gedcom_id FROM ##gedcom WHERE gedcom_name=?") + WT_DB::prepare("SELECT gedcom_id FROM `##gedcom` WHERE gedcom_name=?") ->execute(array($ged_name)) ->fetchOne(); } @@ -2197,16 +2197,16 @@ function get_id_from_gedcom($ged_name, $create=false) { function get_gedcom_setting($gedcom_id, $setting_name, $default_value=null) { return WT_DB::prepare( - "SELECT setting_value FROM ##gedcom_setting WHERE gedcom_id=? AND setting_name=?" + "SELECT setting_value FROM `##gedcom_setting` WHERE gedcom_id=? AND setting_name=?" )->execute(array($gedcom_id, $setting_name))->fetchOne($default_value); } function set_gedcom_setting($ged_id, $setting_name, $setting_value) { if (is_null($setting_value)) { - WT_DB::prepare("DELETE FROM ##gedcom_setting WHERE gedcom_id=? AND setting_name=?") + WT_DB::prepare("DELETE FROM `##gedcom_setting` WHERE gedcom_id=? AND setting_name=?") ->execute(array($ged_id, $setting_name)); } else { - WT_DB::prepare("REPLACE INTO ##gedcom_setting (gedcom_id, setting_name, setting_value) VALUES (?, ?, ?)") + WT_DB::prepare("REPLACE INTO `##gedcom_setting` (gedcom_id, setting_name, setting_value) VALUES (?, ?, ?)") ->execute(array($ged_id, $setting_name, $setting_value)); } } @@ -2217,49 +2217,49 @@ function set_gedcom_setting($ged_id, $setting_name, $setting_value) { function create_user($username, $realname, $email, $password) { try { - WT_DB::prepare("INSERT INTO ##user (user_name, real_name, email, password) VALUES (?, ?, ?, ?)") + WT_DB::prepare("INSERT INTO `##user` (user_name, real_name, email, password) VALUES (?, ?, ?, ?)") ->execute(array($username, $realname, $email, $password)); } catch (PDOException $ex) { // User already exists? } return - WT_DB::prepare("SELECT user_id FROM ##user WHERE user_name=?") + WT_DB::prepare("SELECT user_id FROM `##user` WHERE user_name=?") ->execute(array($username))->fetchOne(); } function rename_user($old_username, $new_username) { - WT_DB::prepare("UPDATE ##user SET user_name=? WHERE user_name =?")->execute(array($new_username, $old_username)); - WT_DB::prepare("UPDATE ##favorites SET fv_username=? WHERE fv_username=?")->execute(array($new_username, $old_username)); - WT_DB::prepare("UPDATE ##news SET n_username =? WHERE n_username =?")->execute(array($new_username, $old_username)); + WT_DB::prepare("UPDATE `##user` SET user_name=? WHERE user_name =?")->execute(array($new_username, $old_username)); + WT_DB::prepare("UPDATE `##favorites` SET fv_username=? WHERE fv_username=?")->execute(array($new_username, $old_username)); + WT_DB::prepare("UPDATE `##news` SET n_username =? WHERE n_username =?")->execute(array($new_username, $old_username)); } function delete_user($user_id) { $user_name=get_user_name($user_id); - WT_DB::prepare("DELETE ##block_setting FROM ##block_setting JOIN ##block USING (block_id) WHERE user_id=?")->execute(array($user_id)); - WT_DB::prepare("DELETE FROM ##block WHERE user_id=?" )->execute(array($user_id)); - WT_DB::prepare("DELETE FROM ##user_gedcom_setting WHERE user_id=?" )->execute(array($user_id)); - WT_DB::prepare("DELETE FROM ##user_setting WHERE user_id=?" )->execute(array($user_id)); - WT_DB::prepare("DELETE FROM ##message WHERE user_id=?" )->execute(array($user_name, $user_name)); - WT_DB::prepare("DELETE FROM ##user WHERE user_id=?" )->execute(array($user_id)); - WT_DB::prepare("DELETE FROM ##favorites WHERE fv_username=?")->execute(array($user_name)); - WT_DB::prepare("DELETE FROM ##news WHERE n_username =?")->execute(array($user_name)); + WT_DB::prepare("DELETE `##block_setting` FROM `##block_setting` JOIN `##block` USING (block_id) WHERE user_id=?")->execute(array($user_id)); + WT_DB::prepare("DELETE FROM `##block` WHERE user_id=?" )->execute(array($user_id)); + WT_DB::prepare("DELETE FROM `##user_gedcom_setting` WHERE user_id=?" )->execute(array($user_id)); + WT_DB::prepare("DELETE FROM `##user_setting` WHERE user_id=?" )->execute(array($user_id)); + WT_DB::prepare("DELETE FROM `##message` WHERE user_id=?" )->execute(array($user_name, $user_name)); + WT_DB::prepare("DELETE FROM `##user` WHERE user_id=?" )->execute(array($user_id)); + WT_DB::prepare("DELETE FROM `##favorites` WHERE fv_username=?")->execute(array($user_name)); + WT_DB::prepare("DELETE FROM `##news` WHERE n_username =?")->execute(array($user_name)); } function get_all_users($order='ASC', $key='realname') { if ($key=='username') { return - WT_DB::prepare("SELECT user_id, user_name FROM ##user ORDER BY user_name") + WT_DB::prepare("SELECT user_id, user_name FROM `##user` ORDER BY user_name") ->fetchAssoc(); } elseif ($key=='realname') { return - WT_DB::prepare("SELECT user_id, user_name FROM ##user ORDER BY real_name") + WT_DB::prepare("SELECT user_id, user_name FROM `##user` ORDER BY real_name") ->fetchAssoc(); } else { return WT_DB::prepare( "SELECT u.user_id, user_name". - " FROM ##user u". - " LEFT JOIN ##user_setting us1 ON (u.user_id=us1.user_id AND us1.setting_name=?)". + " FROM `##user` u". + " LEFT JOIN `##user_setting` us1 ON (u.user_id=us1.user_id AND us1.setting_name=?)". " ORDER BY us1.setting_value {$order}" )->execute(array($key)) ->fetchAssoc(); @@ -2268,20 +2268,20 @@ function get_all_users($order='ASC', $key='realname') { function get_user_count() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##user") + WT_DB::prepare("SELECT COUNT(*) FROM `##user`") ->fetchOne(); } function get_admin_user_count() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##user_setting WHERE setting_name=? AND setting_value=?") + WT_DB::prepare("SELECT COUNT(*) FROM `##user_setting` WHERE setting_name=? AND setting_value=?") ->execute(array('canadmin', 'Y')) ->fetchOne(); } function get_non_admin_user_count() { return - WT_DB::prepare("SELECT COUNT(*) FROM ##user_setting WHERE setting_name=? AND setting_value<>?") + WT_DB::prepare("SELECT COUNT(*) FROM `##user_setting` WHERE setting_name=? AND setting_value<>?") ->execute(array('canadmin', 'Y')) ->fetchOne(); } @@ -2291,8 +2291,8 @@ function get_logged_in_users() { return WT_DB::prepare( "SELECT u.user_id, user_name". - " FROM ##user u". - " JOIN ##user_setting us USING (user_id)". + " FROM `##user` u". + " JOIN `##user_setting` us USING (user_id)". " WHERE setting_name=? AND setting_value=?" ) ->execute(array('loggedin', 'Y')) @@ -2304,9 +2304,9 @@ function get_idle_users($time) { return WT_DB::prepare( "SELECT u.user_id, user_name". - " FROM ##user u". - " JOIN ##user_setting us1 USING (user_id)". - " JOIN ##user_setting us2 USING (user_id)". + " FROM `##user` u". + " JOIN `##user_setting` us1 USING (user_id)". + " JOIN `##user_setting` us2 USING (user_id)". " WHERE us1.setting_name=? AND us1.setting_value=? AND us2.setting_name=?". " AND CAST(us2.setting_value AS UNSIGNED) BETWEEN 1 AND ?" ) @@ -2316,14 +2316,14 @@ function get_idle_users($time) { // Get the ID for a username function get_user_id($username) { - return WT_DB::prepare("SELECT user_id FROM ##user WHERE user_name=?") + return WT_DB::prepare("SELECT user_id FROM `##user` WHERE user_name=?") ->execute(array($username)) ->fetchOne(); } // Get the username for a user ID function get_user_name($user_id) { - return WT_DB::prepare("SELECT user_name FROM ##user WHERE user_id=?") + return WT_DB::prepare("SELECT user_name FROM `##user` WHERE user_id=?") ->execute(array($user_id)) ->fetchOne(); } @@ -2331,8 +2331,8 @@ function get_user_name($user_id) { function get_newest_registered_user() { return WT_DB::prepareLimit( "SELECT u.user_id". - " FROM ##user u". - " LEFT JOIN ##user_setting us ON (u.user_id=us.user_id AND us.setting_name=?) ". + " FROM `##user` u". + " LEFT JOIN `##user_setting` us ON (u.user_id=us.user_id AND us.setting_name=?) ". " ORDER BY us.setting_value DESC", 1 )->execute(array('reg_timestamp')) @@ -2340,12 +2340,12 @@ function get_newest_registered_user() { } function set_user_password($user_id, $password) { - WT_DB::prepare("UPDATE ##user SET password=? WHERE user_id=?") + WT_DB::prepare("UPDATE `##user` SET password=? WHERE user_id=?") ->execute(array($password, $user_id)); } function get_user_password($user_id) { - return WT_DB::prepare("SELECT password FROM ##user WHERE user_id=?") + return WT_DB::prepare("SELECT password FROM `##user` WHERE user_id=?") ->execute(array($user_id)) ->fetchOne(); } @@ -2357,16 +2357,16 @@ function get_user_password($user_id) { function get_user_setting($user_id, $setting_name, $default_value=null) { return WT_DB::prepare( - "SELECT setting_value FROM ##user_setting WHERE user_id=? AND setting_name=?" + "SELECT setting_value FROM `##user_setting` WHERE user_id=? AND setting_name=?" )->execute(array($user_id, $setting_name))->fetchOne($default_value); } function set_user_setting($user_id, $setting_name, $setting_value) { if (is_null($setting_value)) { - WT_DB::prepare("DELETE FROM ##user_setting WHERE user_id=? AND setting_name=?") + WT_DB::prepare("DELETE FROM `##user_setting` WHERE user_id=? AND setting_name=?") ->execute(array($user_id, $setting_name)); } else { - WT_DB::prepare("REPLACE INTO ##user_setting (user_id, setting_name, setting_value) VALUES (?, ?, ?)") + WT_DB::prepare("REPLACE INTO `##user_setting` (user_id, setting_name, setting_value) VALUES (?, ?, ?)") ->execute(array($user_id, $setting_name, $setting_value)); } } @@ -2382,16 +2382,16 @@ function admin_user_exists() { function get_user_gedcom_setting($user_id, $gedcom_id, $setting_name, $default_value=null) { return WT_DB::prepare( - "SELECT setting_value FROM ##user_gedcom_setting WHERE user_id=? AND gedcom_id=? AND setting_name=?" + "SELECT setting_value FROM `##user_gedcom_setting` WHERE user_id=? AND gedcom_id=? AND setting_name=?" )->execute(array($user_id, $gedcom_id, $setting_name))->fetchOne($default_value); } function set_user_gedcom_setting($user_id, $ged_id, $setting_name, $setting_value) { if (is_null($setting_value)) { - WT_DB::prepare("DELETE FROM ##user_gedcom_setting WHERE user_id=? AND gedcom_id=? AND setting_name=?") + WT_DB::prepare("DELETE FROM `##user_gedcom_setting` WHERE user_id=? AND gedcom_id=? AND setting_name=?") ->execute(array($user_id, $ged_id, $setting_name)); } else { - WT_DB::prepare("REPLACE INTO ##user_gedcom_setting (user_id, gedcom_id, setting_name, setting_value) VALUES (?, ?, ?, ?)") + WT_DB::prepare("REPLACE INTO `##user_gedcom_setting` (user_id, gedcom_id, setting_name, setting_value) VALUES (?, ?, ?, ?)") ->execute(array($user_id, $ged_id, $setting_name, $setting_value)); } } @@ -2399,7 +2399,7 @@ function set_user_gedcom_setting($user_id, $ged_id, $setting_name, $setting_valu function get_user_from_gedcom_xref($ged_id, $xref) { return WT_DB::prepare( - "SELECT user_id FROM ##user_gedcom_setting". + "SELECT user_id FROM `##user_gedcom_setting`". " WHERE gedcom_id=? AND setting_name=? AND setting_value=?" )->execute(array($ged_id, 'gedcomid', $xref))->fetchOne(); } @@ -2412,7 +2412,7 @@ function get_user_blocks($user_id) { $blocks=array('main'=>array(), 'side'=>array()); $rows=WT_DB::prepare( "SELECT location, block_id, module_name". - " FROM ##block". + " FROM `##block`". " WHERE user_id=?". " ORDER BY location, block_order" )->execute(array($user_id))->fetchAll(); @@ -2426,7 +2426,7 @@ function get_user_blocks($user_id) { foreach (array('todays_events', 'user_messages', 'user_favorites') as $n=>$block) { if (array_key_exists($block, $active_blocks)) { WT_DB::prepare( - "INSERT INTO ##block (user_id, location, block_order, module_name) VALUES ". + "INSERT INTO `##block` (user_id, location, block_order, module_name) VALUES ". "(?, 'main', ?, ?)" )->execute(array($user_id, $n, $block)); } @@ -2434,7 +2434,7 @@ function get_user_blocks($user_id) { foreach (array('user_welcome', 'random_media', 'upcoming_events', 'logged_in') as $n=>$block) { if (array_key_exists($block, $active_blocks)) { WT_DB::prepare( - "INSERT INTO ##block (user_id, location, block_order, module_name) VALUES ". + "INSERT INTO `##block` (user_id, location, block_order, module_name) VALUES ". "(?, 'side', ?, ?)" )->execute(array($user_id, $n, $block)); } @@ -2447,7 +2447,7 @@ function get_gedcom_blocks($gedcom_id) { $blocks=array('main'=>array(), 'side'=>array()); $rows=WT_DB::prepare( "SELECT location, block_id, module_name". - " FROM ##block". + " FROM `##block`". " WHERE gedcom_id=?". " ORDER BY location, block_order" )->execute(array($gedcom_id))->fetchAll(); @@ -2461,7 +2461,7 @@ function get_gedcom_blocks($gedcom_id) { foreach (array('gedcom_stats', 'gedcom_news', 'gedcom_favorites', 'review_changes') as $n=>$block) { if (array_key_exists($block, $active_blocks)) { WT_DB::prepare( - "INSERT INTO ##block (gedcom_id, location, block_order, module_name) VALUES ". + "INSERT INTO `##block` (gedcom_id, location, block_order, module_name) VALUES ". "(?, 'main', ?, ?)" )->execute(array($gedcom_id, $n, $block)); } @@ -2469,7 +2469,7 @@ function get_gedcom_blocks($gedcom_id) { foreach (array('gedcom_block', 'random_media', 'todays_events', 'logged_in') as $n=>$block) { if (array_key_exists($block, $active_blocks)) { WT_DB::prepare( - "INSERT INTO ##block (gedcom_id, location, block_order, module_name) VALUES ". + "INSERT INTO `##block` (gedcom_id, location, block_order, module_name) VALUES ". "(?, 'side', ?, ?)" )->execute(array($gedcom_id, $n, $block)); } @@ -2481,17 +2481,17 @@ function get_gedcom_blocks($gedcom_id) { function get_block_setting($block_id, $setting_name, $default_value=null) { return WT_DB::prepare( - "SELECT setting_value FROM ##block_setting WHERE block_id=? AND setting_name=?" + "SELECT setting_value FROM `##block_setting` WHERE block_id=? AND setting_name=?" )->execute(array($block_id, $setting_name))->fetchOne($default_value); } function set_block_setting($block_id, $setting_name, $setting_value) { if (is_null($setting_value)) { - WT_DB::prepare("DELETE FROM ##block_setting WHERE block_id=? AND setting_name=?") + WT_DB::prepare("DELETE FROM `##block_setting` WHERE block_id=? AND setting_name=?") ->execute(array($block_id, $setting_name)); } else { - WT_DB::prepare("REPLACE INTO ##block_setting (block_id, setting_name, setting_value) VALUES (?, ?, ?)") + WT_DB::prepare("REPLACE INTO `##block_setting` (block_id, setting_name, setting_value) VALUES (?, ?, ?)") ->execute(array($block_id, $setting_name, $setting_value)); } } @@ -2499,16 +2499,16 @@ function set_block_setting($block_id, $setting_name, $setting_value) { function get_module_setting($module_name, $setting_name, $default_value=null) { return WT_DB::prepare( - "SELECT setting_value FROM ##module_setting WHERE module_name=? AND setting_name=?" + "SELECT setting_value FROM `##module_setting` WHERE module_name=? AND setting_name=?" )->execute(array($module_name, $setting_name))->fetchOne($default_value); } function set_module_setting($module_name, $setting_name, $setting_value) { if (is_null($setting_value)) { - WT_DB::prepare("DELETE FROM ##module_setting WHERE module_name=? AND setting_name=?") + WT_DB::prepare("DELETE FROM `##module_setting` WHERE module_name=? AND setting_name=?") ->execute(array($module_name, $setting_name)); } else { - WT_DB::prepare("REPLACE INTO ##module_setting (module_name, setting_name, setting_value) VALUES (?, ?, ?)") + WT_DB::prepare("REPLACE INTO `##module_setting` (module_name, setting_name, setting_value) VALUES (?, ?, ?)") ->execute(array($module_name, $setting_name, $setting_value)); } } @@ -2524,7 +2524,7 @@ function update_favorites($xref_from, $xref_to, $ged_id=WT_GED_ID) { $ged_name=get_gedcom_from_id($ged_id); return - WT_DB::prepare("UPDATE ##favorites SET fv_gid=? WHERE fv_gid=? AND fv_file=?") + WT_DB::prepare("UPDATE `##favorites` SET fv_gid=? WHERE fv_gid=? AND fv_file=?") ->execute(array($xref_to, $xref_from, $ged_name)) ->rowCount(); } @@ -2536,7 +2536,7 @@ function get_autocomplete_INDI($FILTER, $ged_id=WT_GED_ID) { // search for ids first and request the exact id from FILTER and ids with one additional digit $sql= "SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex". - " FROM ##individuals, ##name". + " FROM `##individuals`, `##name`". " WHERE (i_id=? OR i_id LIKE ?)". " AND i_id=n_id AND i_file=n_file AND i_file=?". " ORDER BY i_id"; @@ -2548,7 +2548,7 @@ function get_autocomplete_INDI($FILTER, $ged_id=WT_GED_ID) { if (count($rows) ==0) { $sql= "SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex". - " FROM ##individuals, ##name". + " FROM `##individuals`, `##name`". " WHERE n_sort LIKE ?". " AND i_id=n_id AND i_file=n_file AND i_file=?". " ORDER BY n_sort"; @@ -2575,7 +2575,7 @@ function get_autocomplete_FAM($FILTER, $ids, $ged_id=WT_GED_ID) { $vars=array_merge($vars, $ids, $ids); } $sql="SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil ". - "FROM ##families ". + "FROM `##families` ". "WHERE {$where} AND f_file=?"; $vars[]=$ged_id; return @@ -2586,7 +2586,7 @@ function get_autocomplete_FAM($FILTER, $ids, $ged_id=WT_GED_ID) { function get_autocomplete_NOTE($FILTER, $ged_id=WT_GED_ID) { $sql="SELECT o_type AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec ". - "FROM ##other ". + "FROM `##other` ". "WHERE o_gedcom LIKE ? AND o_type='NOTE' AND o_file=?"; return WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT) @@ -2596,7 +2596,7 @@ function get_autocomplete_NOTE($FILTER, $ged_id=WT_GED_ID) { function get_autocomplete_SOUR($FILTER, $ged_id=WT_GED_ID) { $sql="SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec ". - "FROM ##sources ". + "FROM `##sources` ". "WHERE (s_name LIKE ? OR s_id LIKE ?) AND s_file=? ORDER BY s_name"; return WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT) @@ -2606,7 +2606,7 @@ function get_autocomplete_SOUR($FILTER, $ged_id=WT_GED_ID) { function get_autocomplete_SOUR_TITL($FILTER, $ged_id=WT_GED_ID) { $sql="SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec ". - "FROM ##sources ". + "FROM `##sources` ". "WHERE s_name LIKE ? AND s_file=? ORDER BY s_name"; return WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT) @@ -2617,7 +2617,7 @@ function get_autocomplete_SOUR_TITL($FILTER, $ged_id=WT_GED_ID) { function get_autocomplete_INDI_BURI_CEME($FILTER, $ged_id=WT_GED_ID) { $sql= "SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex ". - "FROM ##individuals ". + "FROM `##individuals` ". "WHERE i_gedcom LIKE ? AND i_file=?"; return WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT) @@ -2627,7 +2627,7 @@ function get_autocomplete_INDI_BURI_CEME($FILTER, $ged_id=WT_GED_ID) { function get_autocomplete_INDI_SOUR_PAGE($FILTER, $OPTION, $ged_id=WT_GED_ID) { $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex ". - "FROM ##individuals ". + "FROM `##individuals` ". "WHERE i_gedcom LIKE ? AND i_file=?"; return WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT) @@ -2638,7 +2638,7 @@ function get_autocomplete_INDI_SOUR_PAGE($FILTER, $OPTION, $ged_id=WT_GED_ID) { function get_autocomplete_FAM_SOUR_PAGE($FILTER, $OPTION, $ged_id=WT_GED_ID) { $sql= "SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil ". - "FROM ##families ". + "FROM `##families` ". "WHERE f_gedcom LIKE ? AND f_file=?"; return WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT) @@ -2649,7 +2649,7 @@ function get_autocomplete_FAM_SOUR_PAGE($FILTER, $OPTION, $ged_id=WT_GED_ID) { function get_autocomplete_REPO($FILTER, $ged_id=WT_GED_ID) { $sql= "SELECT o_type AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec ". - "FROM ##other ". + "FROM `##other` ". "WHERE (o_gedcom LIKE ? OR o_id LIKE ?) AND o_file=? AND o_type='REPO'"; return WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT) @@ -2660,7 +2660,7 @@ function get_autocomplete_REPO($FILTER, $ged_id=WT_GED_ID) { function get_autocomplete_REPO_NAME($FILTER, $ged_id=WT_GED_ID) { $sql= "SELECT o_type AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec ". - "FROM ##other ". + "FROM `##other` ". "WHERE o_gedcom LIKE ? AND o_file=? AND o_type='REPO'"; return WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT) @@ -2670,7 +2670,7 @@ function get_autocomplete_REPO_NAME($FILTER, $ged_id=WT_GED_ID) { function get_autocomplete_OBJE($FILTER, $ged_id=WT_GED_ID) { $sql="SELECT m_media ". - "FROM ##media ". + "FROM `##media` ". "WHERE (m_titl LIKE ? OR m_media LIKE ?) AND m_gedfile=?"; return WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT) @@ -2680,7 +2680,7 @@ function get_autocomplete_OBJE($FILTER, $ged_id=WT_GED_ID) { function get_autocomplete_SURN($FILTER, $ged_id=WT_GED_ID) { $sql="SELECT DISTINCT n_surname ". - "FROM ##name ". + "FROM `##name` ". "WHERE n_surname LIKE ? AND n_file=? ORDER BY n_surname"; return WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT) @@ -2690,7 +2690,7 @@ function get_autocomplete_SURN($FILTER, $ged_id=WT_GED_ID) { function get_autocomplete_GIVN($FILTER, $ged_id=WT_GED_ID) { $sql="SELECT DISTINCT n_givn ". - "FROM ##name ". + "FROM `##name` ". "WHERE n_givn LIKE ? AND n_file=? ORDER BY n_givn"; return WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT) @@ -2701,33 +2701,33 @@ function get_autocomplete_GIVN($FILTER, $ged_id=WT_GED_ID) { function get_autocomplete_PLAC($FILTER, $ged_id=WT_GED_ID) { $sql= "select p1.p_place". - " from ##places p1". + " from `##places` p1". " where p1.p_place like ? and p1.p_parent_id=0 AND p1.p_file=?". " union ". "select CONCAT(p1.p_place, ', ', p2.p_place)". - " from ##places p1". - " join ##places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)". + " from `##places` p1". + " join `##places` p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)". " where p1.p_place like ? and p2.p_parent_id=0 AND p1.p_file=?". " union ". "select CONCAT(p1.p_place, ', ', p2.p_place, ', ', p3.p_place)". - " from ##places p1". - " join ##places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)". - " join ##places p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)". + " from `##places` p1". + " join `##places` p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)". + " join `##places` p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)". " where p1.p_place like ? and p3.p_parent_id=0 AND p1.p_file=?". " union ". "select CONCAT(p1.p_place, ', ', p2.p_place, ', ', p3.p_place, ', ', p4.p_place)". - " from ##places p1". - " join ##places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)". - " join ##places p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)". - " join ##places p4 ON (p3.p_parent_id=p4.p_id AND p3.p_file=p4.p_file)". + " from `##places` p1". + " join `##places` p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)". + " join `##places` p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)". + " join `##places` p4 ON (p3.p_parent_id=p4.p_id AND p3.p_file=p4.p_file)". " where p1.p_place like ? and p4.p_parent_id=0 AND p1.p_file=?". " union ". "select CONCAT(p1.p_place, ', ', p2.p_place, ', ', p3.p_place, ', ', p4.p_place, ', ', p5.p_place)". - " from ##places p1". - " join ##places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)". - " join ##places p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)". - " join ##places p4 ON (p3.p_parent_id=p4.p_id AND p3.p_file=p4.p_file)". - " join ##places p5 ON (p4.p_parent_id=p5.p_id AND p4.p_file=p5.p_file)". + " from `##places` p1". + " join `##places` p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)". + " join `##places` p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)". + " join `##places` p4 ON (p3.p_parent_id=p4.p_id AND p3.p_file=p4.p_file)". + " join `##places` p5 ON (p4.p_parent_id=p5.p_id AND p4.p_file=p5.p_file)". " where p1.p_place like ? and p5.p_parent_id=0 AND p1.p_file=?"; return diff --git a/includes/functions/functions_edit.php b/includes/functions/functions_edit.php index 4abb56af05..141ddd8f90 100644 --- a/includes/functions/functions_edit.php +++ b/includes/functions/functions_edit.php @@ -218,8 +218,8 @@ function newConnection() { function checkChangeTime($pid, $gedrec, $last_time) { $change=WT_DB::prepare( "SELECT UNIX_TIMESTAMP(change_time) AS change_time, user_name". - " FROM ##change". - " JOIN ##user USING (user_id)". + " FROM `##change`". + " JOIN `##user` USING (user_id)". " WHERE status<>'rejected' AND gedcom_id=? AND xref=? AND change_time>?". " ORDER BY change_id DESC". " LIMIT 1" @@ -281,7 +281,7 @@ function replace_gedrec($gid, $ged_id, $gedrec, $chan=true) { $old_gedrec=find_gedcom_record($gid, $ged_id, true); if ($old_gedrec!=$gedrec) { WT_DB::prepare( - "INSERT INTO ##change (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)" + "INSERT INTO `##change` (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)" )->execute(array( $ged_id, $gid, @@ -314,7 +314,7 @@ function append_gedrec($gedrec, $ged_id) { $gedrec=preg_replace("/^0 @(.*)@/", "0 @$xref@", $gedrec); WT_DB::prepare( - "INSERT INTO ##change (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)" + "INSERT INTO `##change` (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)" )->execute(array( $ged_id, $xref, @@ -337,7 +337,7 @@ function append_gedrec($gedrec, $ged_id) { //-- the given $xref function delete_gedrec($xref, $ged_id) { WT_DB::prepare( - "INSERT INTO ##change (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)" + "INSERT INTO `##change` (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)" )->execute(array( $ged_id, $xref, diff --git a/includes/functions/functions_export.php b/includes/functions/functions_export.php index f62d9c7206..9b97b20034 100644 --- a/includes/functions/functions_export.php +++ b/includes/functions/functions_export.php @@ -135,14 +135,14 @@ function gedcom_header($gedfile) { } // Link to SUBM/SUBN records, if they exist $subn= - WT_DB::prepare("SELECT o_id FROM ##other WHERE o_type=? AND o_file=?") + WT_DB::prepare("SELECT o_id FROM `##other` WHERE o_type=? AND o_file=?") ->execute(array('SUBN', $ged_id)) ->fetchOne(); if ($subn) { $SUBN="\n1 SUBN @{$subn}@"; } $subm= - WT_DB::prepare("SELECT o_id FROM ##other WHERE o_type=? AND o_file=?") + WT_DB::prepare("SELECT o_id FROM `##other` WHERE o_type=? AND o_file=?") ->execute(array('SUBM', $ged_id)) ->fetchOne(); if ($subm) { @@ -284,7 +284,7 @@ function export_gedcom($gedcom, $gedout, $exportOptions) { $buffer=reformat_record_export($head); $recs= - WT_DB::prepare("SELECT i_gedcom FROM ##individuals WHERE i_file=? AND i_id NOT LIKE ? ORDER BY i_id") + WT_DB::prepare("SELECT i_gedcom FROM `##individuals` WHERE i_file=? AND i_id NOT LIKE ? ORDER BY i_id") ->execute(array($ged_id, '%:%')) ->fetchOneColumn(); foreach ($recs as $rec) { @@ -299,7 +299,7 @@ function export_gedcom($gedcom, $gedout, $exportOptions) { } $recs= - WT_DB::prepare("SELECT f_gedcom FROM ##families WHERE f_file=? AND f_id NOT LIKE ? ORDER BY f_id") + WT_DB::prepare("SELECT f_gedcom FROM `##families` WHERE f_file=? AND f_id NOT LIKE ? ORDER BY f_id") ->execute(array($ged_id, '%:%')) ->fetchOneColumn(); foreach ($recs as $rec) { @@ -314,7 +314,7 @@ function export_gedcom($gedcom, $gedout, $exportOptions) { } $recs= - WT_DB::prepare("SELECT s_gedcom FROM ##sources WHERE s_file=? AND s_id NOT LIKE ? ORDER BY s_id") + WT_DB::prepare("SELECT s_gedcom FROM `##sources` WHERE s_file=? AND s_id NOT LIKE ? ORDER BY s_id") ->execute(array($ged_id, '%:%')) ->fetchOneColumn(); foreach ($recs as $rec) { @@ -329,7 +329,7 @@ function export_gedcom($gedcom, $gedout, $exportOptions) { } $recs= - WT_DB::prepare("SELECT o_gedcom FROM ##other WHERE o_file=? AND o_id NOT LIKE ? AND o_type!=? AND o_type!=? ORDER BY o_id") + WT_DB::prepare("SELECT o_gedcom FROM `##other` WHERE o_file=? AND o_id NOT LIKE ? AND o_type!=? AND o_type!=? ORDER BY o_id") ->execute(array($ged_id, '%:%', 'HEAD', 'TRLR')) ->fetchOneColumn(); foreach ($recs as $rec) { @@ -344,7 +344,7 @@ function export_gedcom($gedcom, $gedout, $exportOptions) { } $recs= - WT_DB::prepare("SELECT m_gedrec FROM ##media WHERE m_gedfile=? AND m_media NOT LIKE ? ORDER BY m_media") + WT_DB::prepare("SELECT m_gedrec FROM `##media` WHERE m_gedfile=? AND m_media NOT LIKE ? ORDER BY m_media") ->execute(array($ged_id, '%:%')) ->fetchOneColumn(); foreach ($recs as $rec) { @@ -405,7 +405,7 @@ function export_gramps($gedcom, $gedout, $exportOptions) { $geDownloadGedcom->begin_xml(); $recs= - WT_DB::prepare("SELECT i_id, i_gedcom FROM ##individuals WHERE i_file=? AND i_id NOT LIKE ? ORDER BY i_id") + WT_DB::prepare("SELECT i_id, i_gedcom FROM `##individuals` WHERE i_file=? AND i_id NOT LIKE ? ORDER BY i_id") ->execute(array($ged_id, '%:%')) ->fetchAssoc(); foreach ($recs as $id=>$rec) { @@ -415,7 +415,7 @@ function export_gramps($gedcom, $gedout, $exportOptions) { } $recs= - WT_DB::prepare("SELECT f_id, f_gedcom FROM ##families WHERE f_file=? AND f_id NOT LIKE ? ORDER BY f_id") + WT_DB::prepare("SELECT f_id, f_gedcom FROM `##families` WHERE f_file=? AND f_id NOT LIKE ? ORDER BY f_id") ->execute(array($ged_id, '%:%')) ->fetchAssoc(); foreach ($recs as $id=>$rec) { @@ -425,7 +425,7 @@ function export_gramps($gedcom, $gedout, $exportOptions) { } $recs= - WT_DB::prepare("SELECT s_id, s_gedcom FROM ##sources WHERE s_file=? AND s_id NOT LIKE ? ORDER BY s_id") + WT_DB::prepare("SELECT s_id, s_gedcom FROM `##sources` WHERE s_file=? AND s_id NOT LIKE ? ORDER BY s_id") ->execute(array($ged_id, '%:%')) ->fetchAssoc(); foreach ($recs as $id=>$rec) { @@ -435,7 +435,7 @@ function export_gramps($gedcom, $gedout, $exportOptions) { } $recs= - WT_DB::prepare("SELECT m_media, m_gedrec FROM ##media WHERE m_gedfile=? AND m_media NOT LIKE ? ORDER BY m_media") + WT_DB::prepare("SELECT m_media, m_gedrec FROM `##media` WHERE m_gedfile=? AND m_media NOT LIKE ? ORDER BY m_media") ->execute(array($ged_id, '%:%')) ->fetchAssoc(); foreach ($recs as $id=>$rec) { diff --git a/includes/functions/functions_import.php b/includes/functions/functions_import.php index 322e56c041..009e16051c 100644 --- a/includes/functions/functions_import.php +++ b/includes/functions/functions_import.php @@ -589,16 +589,16 @@ function import_record($gedrec, $ged_id, $update) { static $sql_insert_other=null; if (!$sql_insert_indi) { $sql_insert_indi=WT_DB::prepare( - "INSERT INTO ##individuals (i_id, i_file, i_rin, i_isdead, i_sex, i_gedcom) VALUES (?,?,?,?,?,?)" + "INSERT INTO `##individuals` (i_id, i_file, i_rin, i_isdead, i_sex, i_gedcom) VALUES (?,?,?,?,?,?)" ); $sql_insert_fam=WT_DB::prepare( - "INSERT INTO ##families (f_id, f_file, f_husb, f_wife, f_chil, f_gedcom, f_numchil) VALUES (?,?,?,?,?,?,?)" + "INSERT INTO `##families` (f_id, f_file, f_husb, f_wife, f_chil, f_gedcom, f_numchil) VALUES (?,?,?,?,?,?,?)" ); $sql_insert_sour=WT_DB::prepare( - "INSERT INTO ##sources (s_id, s_file, s_name, s_gedcom, s_dbid) VALUES (?,?,?,?,?)" + "INSERT INTO `##sources` (s_id, s_file, s_name, s_gedcom, s_dbid) VALUES (?,?,?,?,?)" ); $sql_insert_other=WT_DB::prepare( - "INSERT INTO ##other (o_id, o_file, o_type, o_gedcom) VALUES (?,?,?,?)" + "INSERT INTO `##other` (o_id, o_file, o_type, o_gedcom) VALUES (?,?,?,?)" ); } @@ -748,13 +748,13 @@ function update_places($gid, $ged_id, $gedrec) { // Of course, there almost certainly are such places ..... // We need a better solution that attaches multiple names to single places $sql_insert_placelinks=WT_DB::prepare( - "INSERT IGNORE INTO ##placelinks (pl_p_id, pl_gid, pl_file) VALUES (?,?,?)" + "INSERT IGNORE INTO `##placelinks` (pl_p_id, pl_gid, pl_file) VALUES (?,?,?)" ); $sql_insert_places=WT_DB::prepare( - "INSERT INTO ##places (p_id, p_place, p_level, p_parent_id, p_file, p_std_soundex, p_dm_soundex) VALUES (?,?,?,?,?,?,?)" + "INSERT INTO `##places` (p_id, p_place, p_level, p_parent_id, p_file, p_std_soundex, p_dm_soundex) VALUES (?,?,?,?,?,?,?)" ); $sql_select_places=WT_DB::prepare( - "SELECT p_id FROM ##places WHERE p_level=? AND p_file=? AND p_parent_id=? AND p_place LIKE ?" + "SELECT p_id FROM `##places` WHERE p_level=? AND p_file=? AND p_parent_id=? AND p_place LIKE ?" ); } @@ -830,7 +830,7 @@ function update_dates($xref, $ged_id, $gedrec) { static $sql_insert_date=null; if (!$sql_insert_date) { $sql_insert_date=WT_DB::prepare( - "INSERT INTO ##dates (d_day,d_month,d_mon,d_year,d_julianday1,d_julianday2,d_fact,d_gid,d_file,d_type) VALUES (?,?,?,?,?,?,?,?,?,?)" + "INSERT INTO `##dates` (d_day,d_month,d_mon,d_year,d_julianday1,d_julianday2,d_fact,d_gid,d_file,d_type) VALUES (?,?,?,?,?,?,?,?,?,?)" ); } @@ -854,7 +854,7 @@ function update_dates($xref, $ged_id, $gedrec) { function update_rlinks($xref, $ged_id, $gedrec) { static $sql_insert_rlink=null; if (!$sql_insert_rlink) { - $sql_insert_rlink=WT_DB::prepare("INSERT INTO ##remotelinks (r_gid,r_linkid,r_file) VALUES (?,?,?)"); + $sql_insert_rlink=WT_DB::prepare("INSERT INTO `##remotelinks` (r_gid,r_linkid,r_file) VALUES (?,?,?)"); } if (preg_match_all("/\n1 RFN (".WT_REGEX_XREF.')/', $gedrec, $matches, PREG_SET_ORDER)) { @@ -873,7 +873,7 @@ function update_rlinks($xref, $ged_id, $gedrec) { function update_links($xref, $ged_id, $gedrec) { static $sql_insert_link=null; if (!$sql_insert_link) { - $sql_insert_link=WT_DB::prepare("INSERT INTO ##link (l_from,l_to,l_type,l_file) VALUES (?,?,?,?)"); + $sql_insert_link=WT_DB::prepare("INSERT INTO `##link` (l_from,l_to,l_type,l_file) VALUES (?,?,?,?)"); } if (preg_match_all('/^\d+ ('.WT_REGEX_TAG.') @('.WT_REGEX_XREF.')@/m', $gedrec, $matches, PREG_SET_ORDER)) { @@ -898,8 +898,8 @@ function update_names($xref, $ged_id, $record) { static $sql_insert_name_indi=null; static $sql_insert_name_other=null; if (!$sql_insert_name_indi) { - $sql_insert_name_indi=WT_DB::prepare("INSERT INTO ##name (n_file,n_id,n_num,n_type,n_sort,n_full,n_list,n_surname,n_surn,n_givn,n_soundex_givn_std,n_soundex_surn_std,n_soundex_givn_dm,n_soundex_surn_dm) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); - $sql_insert_name_other=WT_DB::prepare("INSERT INTO ##name (n_file,n_id,n_num,n_type,n_sort,n_full,n_list) VALUES (?,?,?,?,?,?,?)"); + $sql_insert_name_indi=WT_DB::prepare("INSERT INTO `##name` (n_file,n_id,n_num,n_type,n_sort,n_full,n_list,n_surname,n_surn,n_givn,n_soundex_givn_std,n_soundex_surn_std,n_soundex_givn_dm,n_soundex_surn_dm) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); + $sql_insert_name_other=WT_DB::prepare("INSERT INTO `##name` (n_file,n_id,n_num,n_type,n_sort,n_full,n_list) VALUES (?,?,?,?,?,?,?)"); } if ($record->getType()!='FAM' && $record->getXref()) { @@ -942,10 +942,10 @@ function insert_media($objrec, $objlevel, $update, $gid, $ged_id, $count) { static $sql_insert_media_mapping=null; if (!$sql_insert_media) { $sql_insert_media=WT_DB::prepare( - "INSERT INTO ##media (m_id, m_media, m_ext, m_titl, m_file, m_gedfile, m_gedrec) VALUES (?, ?, ?, ?, ?, ?, ?)" + "INSERT INTO `##media` (m_id, m_media, m_ext, m_titl, m_file, m_gedfile, m_gedrec) VALUES (?, ?, ?, ?, ?, ?, ?)" ); $sql_insert_media_mapping=WT_DB::prepare( - "INSERT INTO ##media_mapping (mm_id, mm_media, mm_gid, mm_order, mm_gedfile, mm_gedrec) VALUES (?, ?, ?, ?, ?, ?)" + "INSERT INTO `##media_mapping` (mm_id, mm_media, mm_gid, mm_order, mm_gedfile, mm_gedrec) VALUES (?, ?, ?, ?, ?, ?)" ); } @@ -1005,7 +1005,7 @@ function update_media($gid, $ged_id, $gedrec, $update = false) { static $sql_insert_media=null; if (!$sql_insert_media) { $sql_insert_media=WT_DB::prepare( - "INSERT INTO ##media (m_id, m_media, m_ext, m_titl, m_file, m_gedfile, m_gedrec) VALUES (?, ?, ?, ?, ?, ?, ?)" + "INSERT INTO `##media` (m_id, m_media, m_ext, m_titl, m_file, m_gedfile, m_gedrec) VALUES (?, ?, ?, ?, ?, ?, ?)" ); } @@ -1064,7 +1064,7 @@ function update_media($gid, $ged_id, $gedrec, $update = false) { if ($keepmedia) { $old_linked_media= - WT_DB::prepare("SELECT mm_media, mm_gedrec FROM ##media_mapping WHERE mm_gid=? AND mm_gedfile=?") + WT_DB::prepare("SELECT mm_media, mm_gedrec FROM `##media_mapping` WHERE mm_gid=? AND mm_gedfile=?") ->execute(array($gid, $ged_id)) ->fetchAll(PDO::FETCH_NUM); } @@ -1156,25 +1156,25 @@ function update_media($gid, $ged_id, $gedrec, $update = false) { * @param boolean $keepmedia Whether or not to keep media and media links in the tables */ function empty_database($ged_id, $keepmedia) { - WT_DB::prepare("DELETE FROM ##individuals WHERE i_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##families WHERE f_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##sources WHERE s_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##other WHERE o_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##places WHERE p_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##placelinks WHERE pl_file=?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##remotelinks WHERE r_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##name WHERE n_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##dates WHERE d_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##change WHERE gedcom_id=?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##individuals` WHERE i_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##families` WHERE f_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##sources` WHERE s_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##other` WHERE o_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##places` WHERE p_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##placelinks` WHERE pl_file=?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##remotelinks` WHERE r_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##name` WHERE n_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##dates` WHERE d_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##change` WHERE gedcom_id=?")->execute(array($ged_id)); if ($keepmedia) { - WT_DB::prepare("DELETE FROM ##link WHERE l_file =? AND l_type <>'OBJE'")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##next_id WHERE gedcom_id=? AND record_type<>'OBJE'")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##link` WHERE l_file =? AND l_type <>'OBJE'")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##next_id` WHERE gedcom_id=? AND record_type<>'OBJE'")->execute(array($ged_id)); } else { - WT_DB::prepare("DELETE FROM ##link WHERE l_file =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##next_id WHERE gedcom_id =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##media WHERE m_gedfile =?")->execute(array($ged_id)); - WT_DB::prepare("DELETE FROM ##media_mapping WHERE mm_gedfile=?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##link` WHERE l_file =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##next_id` WHERE gedcom_id =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##media` WHERE m_gedfile =?")->execute(array($ged_id)); + WT_DB::prepare("DELETE FROM `##media_mapping` WHERE mm_gedfile=?")->execute(array($ged_id)); } //-- clear all of the cache files for this gedcom @@ -1185,8 +1185,8 @@ function empty_database($ged_id, $keepmedia) { function accept_all_changes($xref, $ged_id) { $changes=WT_DB::prepare( "SELECT change_id, gedcom_name, old_gedcom, new_gedcom". - " FROM ##change c". - " JOIN ##gedcom g USING (gedcom_id)". + " FROM `##change` c". + " JOIN `##gedcom` g USING (gedcom_id)". " WHERE c.status='pending' AND xref=? AND gedcom_id=?". " ORDER BY change_id" )->execute(array($xref, $ged_id))->fetchAll(); @@ -1199,7 +1199,7 @@ function accept_all_changes($xref, $ged_id) { update_record($change->new_gedcom, $ged_id, false); } WT_DB::prepare( - "UPDATE ##change". + "UPDATE `##change`". " SET status='accepted'". " WHERE status='pending' AND xref=? AND gedcom_id=?" )->execute(array($xref, $ged_id)); @@ -1210,7 +1210,7 @@ function accept_all_changes($xref, $ged_id) { // Accept all pending changes for a specified record function reject_all_changes($xref, $ged_id) { WT_DB::prepare( - "UPDATE ##change". + "UPDATE `##change`". " SET status='rejected'". " WHERE status='pending' AND xref=? AND gedcom_id=?" )->execute(array($xref, $ged_id)); @@ -1247,44 +1247,44 @@ function update_record($gedrec, $ged_id, $delete) { // TODO deleting unlinked places can be done more efficiently in a single query $placeids= - WT_DB::prepare("SELECT pl_p_id FROM ##placelinks WHERE pl_gid=? AND pl_file=?") + WT_DB::prepare("SELECT pl_p_id FROM `##placelinks` WHERE pl_gid=? AND pl_file=?") ->execute(array($gid, $ged_id)) ->fetchOneColumn(); - WT_DB::prepare("DELETE FROM ##placelinks WHERE pl_gid=? AND pl_file=?")->execute(array($gid, $ged_id)); - WT_DB::prepare("DELETE FROM ##dates WHERE d_gid =? AND d_file =?")->execute(array($gid, $ged_id)); + WT_DB::prepare("DELETE FROM `##placelinks` WHERE pl_gid=? AND pl_file=?")->execute(array($gid, $ged_id)); + WT_DB::prepare("DELETE FROM `##dates` WHERE d_gid =? AND d_file =?")->execute(array($gid, $ged_id)); //-- delete any unlinked places foreach ($placeids as $p_id) { $num= - WT_DB::prepare("SELECT count(pl_p_id) FROM ##placelinks WHERE pl_p_id=? AND pl_file=?") + WT_DB::prepare("SELECT count(pl_p_id) FROM `##placelinks` WHERE pl_p_id=? AND pl_file=?") ->execute(array($p_id, $ged_id)) ->fetchOne(); if ($num==0) { - WT_DB::prepare("DELETE FROM ##places WHERE p_id=? AND p_file=?")->execute(array($p_id, $ged_id)); + WT_DB::prepare("DELETE FROM `##places` WHERE p_id=? AND p_file=?")->execute(array($p_id, $ged_id)); } } - WT_DB::prepare("DELETE FROM ##media_mapping WHERE mm_gid=? AND mm_gedfile=?")->execute(array($gid, $ged_id)); - WT_DB::prepare("DELETE FROM ##remotelinks WHERE r_gid=? AND r_file=?")->execute(array($gid, $ged_id)); - WT_DB::prepare("DELETE FROM ##name WHERE n_id=? AND n_file=?")->execute(array($gid, $ged_id)); - WT_DB::prepare("DELETE FROM ##link WHERE l_from=? AND l_file=?")->execute(array($gid, $ged_id)); + WT_DB::prepare("DELETE FROM `##media_mapping` WHERE mm_gid=? AND mm_gedfile=?")->execute(array($gid, $ged_id)); + WT_DB::prepare("DELETE FROM `##remotelinks` WHERE r_gid=? AND r_file=?")->execute(array($gid, $ged_id)); + WT_DB::prepare("DELETE FROM `##name` WHERE n_id=? AND n_file=?")->execute(array($gid, $ged_id)); + WT_DB::prepare("DELETE FROM `##link` WHERE l_from=? AND l_file=?")->execute(array($gid, $ged_id)); switch ($type) { case 'INDI': - WT_DB::prepare("DELETE FROM ##individuals WHERE i_id=? AND i_file=?")->execute(array($gid, $ged_id)); + WT_DB::prepare("DELETE FROM `##individuals` WHERE i_id=? AND i_file=?")->execute(array($gid, $ged_id)); break; case 'FAM': - WT_DB::prepare("DELETE FROM ##families WHERE f_id=? AND f_file=?")->execute(array($gid, $ged_id)); + WT_DB::prepare("DELETE FROM `##families` WHERE f_id=? AND f_file=?")->execute(array($gid, $ged_id)); break; case 'SOUR': - WT_DB::prepare("DELETE FROM ##sources WHERE s_id=? AND s_file=?")->execute(array($gid, $ged_id)); + WT_DB::prepare("DELETE FROM `##sources` WHERE s_id=? AND s_file=?")->execute(array($gid, $ged_id)); break; case 'OBJE': - WT_DB::prepare("DELETE FROM ##media WHERE m_media=? AND m_gedfile=?")->execute(array($gid, $ged_id)); + WT_DB::prepare("DELETE FROM `##media` WHERE m_media=? AND m_gedfile=?")->execute(array($gid, $ged_id)); break; default: - WT_DB::prepare("DELETE FROM ##other WHERE o_id=? AND o_file=?")->execute(array($gid, $ged_id)); + WT_DB::prepare("DELETE FROM `##other` WHERE o_id=? AND o_file=?")->execute(array($gid, $ged_id)); break; } diff --git a/includes/functions/functions_mediadb.php b/includes/functions/functions_mediadb.php index 5739d9a9e8..b56d2f9b94 100644 --- a/includes/functions/functions_mediadb.php +++ b/includes/functions/functions_mediadb.php @@ -190,12 +190,12 @@ function get_medialist($currentdir = false, $directory = "", $linkonly = false, $myDir = str_replace($MEDIA_DIRECTORY, "", $directory); if ($random) { $rows= - WT_DB::prepare("SELECT m_id, m_file, m_media, m_gedrec, m_titl, m_gedfile FROM ##media WHERE m_gedfile=? ORDER BY RAND() LIMIT 5") + WT_DB::prepare("SELECT m_id, m_file, m_media, m_gedrec, m_titl, m_gedfile FROM `##media` WHERE m_gedfile=? ORDER BY RAND() LIMIT 5") ->execute(array(WT_GED_ID)) ->fetchAll(); } else { $rows= - WT_DB::prepare("SELECT m_id, m_file, m_media, m_gedrec, m_titl, m_gedfile FROM ##media WHERE m_gedfile=? AND (m_file LIKE ? OR m_file LIKE ?) ORDER BY m_id desc") + WT_DB::prepare("SELECT m_id, m_file, m_media, m_gedrec, m_titl, m_gedfile FROM `##media` WHERE m_gedfile=? AND (m_file LIKE ? OR m_file LIKE ?) ORDER BY m_id desc") ->execute(array(WT_GED_ID, "%{$myDir}%", "%://%")) ->fetchAll(); } @@ -1624,7 +1624,7 @@ function PrintMediaLinks($links, $size = "small") { function get_media_id_from_file($filename){ return - WT_DB::prepare("SELECT m_media FROM ##media WHERE m_file LIKE ?") + WT_DB::prepare("SELECT m_media FROM `##media` WHERE m_file LIKE ?") ->execute(array("%{$filename}")) ->fetchOne(); } @@ -1669,7 +1669,7 @@ function picture_clip($person_id, $image_id, $filename, $thumbDir) { // This gets the gedrec $gedrec= - WT_DB::prepare("SELECT m_gedrec FROM ##media WHERE m_media=? AND m_gedfile=?") + WT_DB::prepare("SELECT m_gedrec FROM `##media` WHERE m_media=? AND m_gedfile=?") ->execute(array($image_id, WT_GED_ID)) ->fetchOne(); diff --git a/includes/functions/functions_print_facts.php b/includes/functions/functions_print_facts.php index d7ab49307b..e75e97f481 100644 --- a/includes/functions/functions_print_facts.php +++ b/includes/functions/functions_print_facts.php @@ -574,7 +574,7 @@ function print_media_links($factrec, $level, $pid='') { $media_id = str_replace("@", "", trim($omatch[$objectNum][1])); if (displayDetailsById($media_id, "OBJE")) { $row= - WT_DB::prepare("SELECT m_titl, m_file, m_gedrec FROM ##media where m_media=? AND m_gedfile=?") + WT_DB::prepare("SELECT m_titl, m_file, m_gedrec FROM `##media` where m_media=? AND m_gedfile=?") ->execute(array($media_id, WT_GED_ID)) ->fetchOneRow(PDO::FETCH_ASSOC); @@ -1279,7 +1279,7 @@ function print_main_media($pid, $level=1, $related=false, $noedit=false) { $media_found = false; $sqlmm = "SELECT "; - $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM ##media, ##media_mapping where "; + $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM `##media`, `##media_mapping` where "; $sqlmm .= "mm_gid IN ("; $vars=array(); $i=0; diff --git a/includes/hitcount.php b/includes/hitcount.php index 0d444161eb..142a8ddc10 100644 --- a/includes/hitcount.php +++ b/includes/hitcount.php @@ -71,7 +71,7 @@ default: } if ($page_parameter) { $hitCount=WT_DB::prepare( - "SELECT page_count FROM ##hit_counter". + "SELECT page_count FROM `##hit_counter`". " WHERE gedcom_id=? AND page_name=? AND page_parameter=?" )->execute(array(WT_GED_ID, WT_SCRIPT_NAME, $page_parameter))->fetchOne(); @@ -81,12 +81,12 @@ if ($page_parameter) { if (is_null($hitCount)) { $hitCount=1; WT_DB::prepare( - "INSERT INTO ##hit_counter (gedcom_id, page_name, page_parameter, page_count) VALUES (?, ?, ?, ?)" + "INSERT INTO `##hit_counter` (gedcom_id, page_name, page_parameter, page_count) VALUES (?, ?, ?, ?)" )->execute(array(WT_GED_ID, WT_SCRIPT_NAME, $page_parameter, $hitCount)); } else { $hitCount++; WT_DB::prepare( - "UPDATE ##hit_counter SET page_count=?". + "UPDATE `##hit_counter` SET page_count=?". " WHERE gedcom_id=? AND page_name=? AND page_parameter=?" )->execute(array($hitCount, WT_GED_ID, WT_SCRIPT_NAME, $page_parameter)); } diff --git a/includes/media_reorder.php b/includes/media_reorder.php index 66f9b35bf1..83955681eb 100644 --- a/includes/media_reorder.php +++ b/includes/media_reorder.php @@ -116,7 +116,7 @@ require_once WT_ROOT.'includes/functions/functions_print_facts.php'; $media_found = false; $sqlmm = "SELECT DISTINCT "; - $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM ##media, ##media_mapping WHERE "; + $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM `##media`, `##media_mapping` WHERE "; $sqlmm .= "mm_gid IN ("; $i=0; $vars=array(); diff --git a/includes/media_reorder_count.php b/includes/media_reorder_count.php index 236d52013c..e6484a43b0 100644 --- a/includes/media_reorder_count.php +++ b/includes/media_reorder_count.php @@ -60,7 +60,7 @@ if ($ct>0) { } // Use database to get details of indi related items --------------------------------------------- $sqlmm = "SELECT DISTINCT "; - $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM ##media, ##media_mapping WHERE "; + $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM `##media`, `##media_mapping` WHERE "; $sqlmm .= "mm_gid IN ("; $vars=array(); $i=0; diff --git a/includes/session_spider.php b/includes/session_spider.php index 17a5f74c7c..7ae6deeae2 100644 --- a/includes/session_spider.php +++ b/includes/session_spider.php @@ -80,7 +80,7 @@ function gen_spider_session_name($bot_name, $bot_language) { // Note: you may need to blcok IPv6 addresses as well as IPv4 ones. try { $banned_ip=WT_DB::prepareLimit( - "SELECT ip_address, comment FROM ##ip_address". + "SELECT ip_address, comment FROM `##ip_address`". " WHERE category='banned' AND ? LIKE REPLACE(ip_address, '*', '%')", 1 )->execute(array($_SERVER['REMOTE_ADDR']))->fetchOneRow(); @@ -336,7 +336,7 @@ if ($SEARCH_SPIDER && in_array(WT_SCRIPT_NAME, $bots_not_allowed)) { // mode or update the table pgv_ip_address directly. try { $search_engine=WT_DB::prepareLimit( - "SELECT ip_address, comment FROM ##ip_address". + "SELECT ip_address, comment FROM `##ip_address`". " WHERE category='search-engine' AND ? LIKE REPLACE(ip_address, '*', '%')", 1 )->execute(array($_SERVER['REMOTE_ADDR']))->fetchOneRow(); diff --git a/includes/set_gedcom_defaults.php b/includes/set_gedcom_defaults.php index b24ac56b44..b438b823dc 100644 --- a/includes/set_gedcom_defaults.php +++ b/includes/set_gedcom_defaults.php @@ -52,7 +52,7 @@ WT_Module::setDefaultAccess($ged_id); // General settings //////////////////////////////////////////////////////////////////////////////// $statement=WT_DB::prepare( - "INSERT IGNORE INTO ##gedcom_setting (gedcom_id, setting_name, setting_value) VALUES (?, ?, ?)"); + "INSERT IGNORE INTO `##gedcom_setting` (gedcom_id, setting_name, setting_value) VALUES (?, ?, ?)"); $statement->execute(array($ged_id, 'title', i18n::translate('Genealogy from [%s]', $ged_name))); $statement->execute(array($ged_id, 'imported', 0)); |
