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


PHP Connection::expandArguments方法代碼示例

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


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

示例1: expandArguments

 /**
  * {@inheritdoc}
  */
 protected function expandArguments(&$query, &$args)
 {
     $modified = parent::expandArguments($query, $args);
     // The PDO SQLite driver always replaces placeholders with strings, which
     // breaks numeric expressions (e.g., COUNT(*) >= :count). Replace numeric
     // placeholders in the query to work around this bug.
     // @see http://bugs.php.net/bug.php?id=45259
     if (empty($args)) {
         return $modified;
     }
     // Check if $args is a simple numeric array.
     if (range(0, count($args) - 1) === array_keys($args)) {
         // In that case, we have unnamed placeholders.
         $count = 0;
         $new_args = array();
         foreach ($args as $value) {
             if (is_float($value) || is_int($value) || is_numeric($value)) {
                 if (is_float($value)) {
                     // Force the conversion to float so as not to loose precision
                     // in the automatic cast.
                     $value = sprintf('%F', $value);
                 }
                 $query = substr_replace($query, $value, strpos($query, '?'), 1);
             } else {
                 $placeholder = ':db_statement_placeholder_' . $count++;
                 $query = substr_replace($query, $placeholder, strpos($query, '?'), 1);
                 $new_args[$placeholder] = $value;
             }
         }
         $args = $new_args;
         $modified = TRUE;
     } else {
         foreach ($args as $placeholder => $value) {
             if (is_float($value) || is_int($value) || is_numeric($value)) {
                 if (is_float($value)) {
                     // Force the conversion to float so as not to loose precision
                     // in the automatic cast.
                     $value = sprintf('%F', $value);
                 }
                 // We will remove this placeholder from the query as PDO throws an
                 // exception if the number of placeholders in the query and the
                 // arguments does not match.
                 unset($args[$placeholder]);
                 // PDO allows placeholders to not be prefixed by a colon. See
                 // http://marc.info/?l=php-internals&m=111234321827149&w=2 for
                 // more.
                 if ($placeholder[0] != ':') {
                     $placeholder = ":{$placeholder}";
                 }
                 // When replacing the placeholders, make sure we search for the
                 // exact placeholder. For example, if searching for
                 // ':db_placeholder_1', do not replace ':db_placeholder_11'.
                 $query = preg_replace('/' . preg_quote($placeholder, '/') . '\\b/', $value, $query);
                 $modified = TRUE;
             }
         }
     }
     return $modified;
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:62,代碼來源:Connection.php


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