查了很久才查到需要的 不过不全   
 
现在把X2的发出来  
 
首先block_sql.php文件  
 
大家先保存到 source\class\block\html目录下 
- <?php
 
 - /**
 
 - * 
 
 - * 
 
 - * 
 
 - */
 
 - if(!defined('IN_DISCUZ')) {
 
 - exit('Access Denied');
 
 - }
 
 - require_once libfile('commonblock_html', 'class/block/html');
 
 - class block_sql extends commonblock_html {
 
 - function block_sql() {}
 
 - function name() {
 
 - return 'SQL脚本';
 
 - }
 
 - function getsetting() {
 
 - global $_G;
 
 - $settings = array(
 
 - 'sql' => array(
 
 - 'title' => 'SQL语句',
 
 - 'type' => 'textarea',
 
 - 'default' => 'SELECT *
 
 - FROM `pre_forum_forum`'
 
 - ),
 
  
- /*'fieldlist' => array(
 
 - 'title' => '可引用字段',
 
 - 'type' => 'textarea',
 
 - 'default' => '{$tablepre} '
 
 - ),*/
 
  
- 'template' => array(
 
 - 'title' => 'HTML模板',
 
 - 'type' => 'textarea',
 
 - 'default' => '[node]{name}<BR>[/node]'
 
 - ),
 
  
- 'start' => array(
 
 - 'title' => '起始数据行数',
 
 - 'type' => 'text',
 
 - 'default' => 0
 
 - ),
 
 - 'limit' => array(
 
 - 'title' => '显示数据条数',
 
 - 'type' => 'text',
 
 - 'default' => 5
 
 - )
 
 - );
 
 - return $settings;
 
 - }
 
 - function getdata($style, $parameter) {
 
 - require_once libfile('function/home');
 
 - /// $return = getstr($parameter['content'], '', 1, 0, 1, 0, 1);
 
 - ///
 
 - global $_G;
 
 - $tablepre = $_G['config']['db']['1']['tablepre'];
 
 - $sql = !empty($parameter['sql']) ? ($parameter['sql']) : '';
 
 - $start = !empty($parameter['start']) ? intval($parameter['start']) : 0;
 
 - $limit = !empty($parameter['limit']) ? intval($parameter['limit']) : 5;
 
  
- $writedata = '';
 
 - if ($sql != '')
 
 - {
 
 - $searchs1 = $replaces1 = array();
 
 - $searchs1[] = '{$tablepre}';
 
 - $replaces1[] = $tablepre;//'`'.$dbname.'`.'.$tablepre;
 
 - $sql = str_replace($searchs1, $replaces1, stripslashes($sql));
 
 - $sql = ltrim(strtolower($sql));
 
 - $i = strpos($sql , 'select');
 
 - if ($i != 0){
 
 - $writedata = '只能定义SELECT语句';
 
 - return array('html' => $writedata, 'data' => null);
 
 - }
 
 - $sqldata = $sql.' limit '.$start.','.$limit.';';
 
 - $query = DB::query($sqldata);
 
  
- $writedata = '';
 
 - $requesttemplatebody = '';
 
 - $requesttemplate = stripslashes($parameter['template']);
 
 - if(preg_match("/\[node\](.+?)\[\/node\]/is", $requesttemplate, $node)) {
 
 - $requesttemplatebody = $requesttemplate;
 
 - $requesttemplate = $node[1];
 
 - }
 
 - while($thread = DB::fetch($query)) {
 
 - $searchs = $replaces = array();
 
 - foreach(array_keys($thread) as $key) {
 
 - $searchs[] = '{'.$key.'}';
 
 - $replaces[] = htmlspecialchars($thread[$key]);
 
 - $searchs[] = '{rawurlencode('.$key.')}';
 
 - $replaces[] = rawurlencode($thread[$key]);
 
 - }
 
 - $writedata .= str_replace($searchs, $replaces, $requesttemplate);
 
 - }
 
 - if ($requesttemplatebody){
 
 - $oldwritedata = $writedata;
 
 - $writedata = str_replace($node[0], $oldwritedata, $requesttemplatebody); 
 
 - }
 
 - }else{
 
 - $writedata = '没有定义SQL';
 
 - }
 
 - ///
 
 - return array('html' => $writedata, 'data' => null);
 
 - }
 
 - }
 
 - ?>
 
  复制代码 
然后在 source/language/ 找到 lang_blockclass.php文件 在 'blockclass_html_script_category' => '分类信息', 下面加上'sql' => 'SQL脚本', 保存,开始实验! 
 
 |