當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Database::quote方法代碼示例

本文整理匯總了PHP中Fisharebest\Webtrees\Database::quote方法的典型用法代碼示例。如果您正苦於以下問題:PHP Database::quote方法的具體用法?PHP Database::quote怎麽用?PHP Database::quote使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Fisharebest\Webtrees\Database的用法示例。


在下文中一共展示了Database::quote方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: givenAlpha

 /**
  * Get a list of initial given name letters for indilist.php and famlist.php
  *
  * @param Tree   $tree   Find names in this tree
  * @param string $surn   if set, only consider people with this surname
  * @param string $salpha if set, only consider surnames starting with this letter
  * @param bool   $marnm  if set, include married names
  * @param bool   $fams   if set, only consider individuals with FAMS records
  *
  * @return int[]
  */
 public static function givenAlpha(Tree $tree, $surn, $salpha, $marnm, $fams)
 {
     $alphas = array();
     $sql = "SELECT SQL_CACHE COUNT(DISTINCT n_id)" . " FROM `##name`" . ($fams ? " JOIN `##link` ON (n_id=l_from AND n_file=l_file AND l_type='FAMS') " : "") . " WHERE n_file=" . $tree->getTreeId() . " " . ($marnm ? "" : " AND n_type!='_MARNM'");
     if ($surn) {
         $sql .= " AND n_surn=" . Database::quote($surn) . " COLLATE '" . I18N::collation() . "'";
     } elseif ($salpha == ',') {
         $sql .= " AND n_surn=''";
     } elseif ($salpha == '@') {
         $sql .= " AND n_surn='@N.N.'";
     } elseif ($salpha) {
         $sql .= " AND " . self::getInitialSql('n_surn', $salpha);
     } else {
         // All surnames
         $sql .= " AND n_surn NOT IN ('', '@N.N.')";
     }
     // Fetch all the letters in our alphabet, whether or not there
     // are any names beginning with that letter. It looks better to
     // show the full alphabet, rather than omitting rare letters such as X
     foreach (self::getAlphabetForLocale(WT_LOCALE) as $letter) {
         $count = Database::prepare($sql . " AND " . self::getInitialSql('n_givn', $letter))->fetchOne();
         $alphas[$letter] = $count;
     }
     // Now fetch initial letters that are not in our alphabet,
     // including "@" (for "@N.N.") and "" for no surname
     $sql = "SELECT SQL_CACHE initial, total FROM (SELECT UPPER(LEFT(n_givn, 1)) AS initial, COUNT(DISTINCT n_id) AS total" . " FROM `##name` " . ($fams ? " JOIN `##link` ON (n_id = l_from AND n_file = l_file AND l_type = 'FAMS') " : "") . " WHERE n_file = :tree_id" . ($marnm ? "" : " AND n_type != '_MARNM'");
     $args = array('tree_id' => $tree->getTreeId());
     if ($surn) {
         $sql .= " AND n_surn COLLATE :collate_1 = :surn";
         $args['collate_1'] = I18N::collation();
         $args['surn'] = $surn;
     } elseif ($salpha === ',') {
         $sql .= " AND n_surn = ''";
     } elseif ($salpha === '@') {
         $sql .= " AND n_surn = '@N.N.'";
     } elseif ($salpha) {
         $sql .= " AND " . self::getInitialSql('n_surn', $salpha);
     } else {
         // All surnames
         $sql .= " AND n_surn NOT IN ('', '@N.N.')";
     }
     foreach (self::getAlphabetForLocale(WT_LOCALE) as $letter) {
         $sql .= " AND n_givn NOT LIKE '" . $letter . "%' COLLATE " . I18N::collation();
     }
     $sql .= " GROUP BY UPPER(LEFT(n_givn, 1))) AS subquery ORDER BY initial = '@', initial = '', initial";
     foreach (Database::prepare($sql)->execute($args)->fetchAssoc() as $alpha => $count) {
         $alphas[$alpha] = $count;
     }
     return $alphas;
 }
開發者ID:tronsmit,項目名稱:webtrees,代碼行數:61,代碼來源:QueryName.php


注:本文中的Fisharebest\Webtrees\Database::quote方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。