本文整理汇总了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;
}