本文整理匯總了PHP中moodle_database::sql_intersect方法的典型用法代碼示例。如果您正苦於以下問題:PHP moodle_database::sql_intersect方法的具體用法?PHP moodle_database::sql_intersect怎麽用?PHP moodle_database::sql_intersect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類moodle_database
的用法示例。
在下文中一共展示了moodle_database::sql_intersect方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sql_intersect
/**
* Returns the SQL that allows to find intersection of two or more queries
*
* @since Moodle 2.8
*
* @param array $selects array of SQL select queries, each of them only returns fields with the names from $fields
* @param string $fields comma-separated list of fields
* @return string SQL query that will return only values that are present in each of selects
*/
public function sql_intersect($selects, $fields)
{
if (count($selects) <= 1) {
return parent::sql_intersect($selects, $fields);
}
$fields = preg_replace('/\\s/', '', $fields);
static $aliascnt = 0;
$falias = 'intsctal' . $aliascnt++;
$rv = "SELECT {$falias}." . preg_replace('/,/', ',' . $falias . '.', $fields) . " FROM ({$selects['0']}) {$falias}";
for ($i = 1; $i < count($selects); $i++) {
$alias = 'intsctal' . $aliascnt++;
$rv .= " JOIN (" . $selects[$i] . ") {$alias} ON " . join(' AND ', array_map(create_function('$a', 'return "' . $falias . '.$a = ' . $alias . '.$a";'), preg_split('/,/', $fields)));
}
return $rv;
}