经过检查数据库,发现是数据库forum_attachment中tableid的数值不正确造成的,修复对应关系即可,修复代码如下(请注意修改高亮的行):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
<?php /** * @name AlonePHP * @version 0.1 * @author Tom <tom@awaysoft.com> * @date 2014-08-20 * @description AlonePHP是一个单文件框架,适用于制作简单的小工具,支持网页及命令模式 * @copyright Apache License, Version 2.0 */ define('ALONE_ROOT', dirname(__FILE__)); define('IS_CLI', php_sapi_name() === 'cli'); $config = [ 'db' => [ 'dsn' => 'mysql:host=localhost;dbname=gtk', 'user' => 'gtk', 'pass' => 'gtk', 'driver_options' => [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8';"] ], ]; $attachDBs = []; function findTable($aid) { global $attachDBs; for ($i = 0; $i <=9; ++$i) { $table = $attachDBs[$i]; foreach ($table as $row) { if ($row['aid'] === $aid) { return $i; } } } return -1; } function IndexController() { $db = new Db(); global $attachDBs; $table_pre = 'gtk_forum_attachment'; for ($i = 0; $i <= 9; ++$i) { $sql = "select * from {$table_pre}_{$i}"; $rs = $db->query($sql); $result = $rs->fetchAll(PDO::FETCH_ASSOC); array_push($attachDBs, $result); } $sql = "select * from {$table_pre}"; $rs = $db->query($sql); $result = $rs->fetchAll(PDO::FETCH_ASSOC); foreach($result as $row) { $aid = $row['aid']; $tid = findTable($aid); if ($tid !== -1) { $sql = "update {$table_pre} set tableid={$tid} where aid={$aid}"; echo $aid . ':' . findTable($aid) . "\n"; $db->exec($sql); } } } /** * 默认控制器 * Default Controller */ if (!function_exists('IndexController')) { function IndexController() { template('Index'); } } /** * 默认控制器模板 * Default Controller Template */ if (!function_exists('IndexTemplate')) { function IndexTemplate($args) { echo IS_CLI ? "欢迎使用AlonePHP框架\n" : '<meta charset="utf-8">欢迎使用AlonePHP框架'; } } /** * 初始化函数,可以做权限验证,数据初始化等等 * Initiazation Function, you can use it to check author or others */ if (!function_exists('init')) { function init() { } } /** * 框架运行函数 * Framework run function */ function run() { /* 初始化 */ init(); /* 获取控制器 */ if (IS_CLI) { /* 获取命令模式控制器 */ $controller = param_get(1); } else { /* 获取网页模式 */ $controller = get('c'); } if (!$controller) { $controller = 'Index'; } /* 移交控制权到相应的控制器 */ controller($controller); } /** * @description 模板输出接口函数(Template function) * @param string $name 模板名称/Template Name * @param mixed $args 传递到模板的参数,建议用关联数组/Template Args, better using relate array. */ function template($name, $args = '') { $templateName = $name . 'Template'; if (function_exists($templateName)) { $templateName($args); } else { template('Error', "模板函数{$templateName}未找到!"); } } /** * @description 控制器接口函数 * @param string $name 控制器名称/Controller Name */ function controller($name) { $controllerName = $name . 'Controller'; if (function_exists($controllerName)) { $controllerName(); } else { template('Error', "控制器函数{$controllerName}未找到!"); } } /** * @description 程序打开参数个数 * @return integer 返回程序的参数个数 The Number of Params */ function param_count() { if (IS_CLI) { global $argc; return $argc - 1; } else { return 0; } } /** * @description 获取程序参数 * @param integer $index, 参数的位置(The position of params) * @return string|boolean 返回第index个参数的值,The value of Params[$index]; */ function param_get($index) { if (IS_CLI) { global $argc, $argv; if ($index >= $argc) { return false; } else { return $argv[$index]; } } else { return false; } } /** GET方法 * @param string $name GET参数/The key of GET * @param string $filter 过滤函数/Filter function * @param string $default 默认值/Default Value * @return string */ function get($name, $filter = 'htmlspecialchars', $default = '') { if (!isset($_GET[$name])) { $result = $default; } else { $result = $_GET[$name]; } return $filter($result); } /** POST方法 * @param string $name POST参数/The key of POST * @param string $filter 过滤函数/Filter function * @param string $default 默认值/Default Value * @return string */ function post($name, $filter = 'htmlspecialchars', $default = '') { if (!isset($_POST[$name])) { $result = $default; } else { $result = $_POST[$name]; } return $filter($result); } /* 默认输出错误信息函数 Default Error Template */ function ErrorTemplate($args) { echo $args; } /* 数据库类,继承自PDO */ class Db extends PDO{ private $config = [ 'dsn' => '', 'user' => '', 'pass' => '', 'driver_options' => [] ]; public function __construct($configNew = null) { if (!$configNew) { global $config; $configNew = $config['db']; } $this->config = array_merge($this->config, $configNew); try { parent::__construct($this->config['dsn'], $this->config['user'], $this->config['pass'], $this->config['driver_options']); } catch (Exception $e) { trigger_error('数据库连接失败:' . $e->getMessage(), E_USER_ERROR); } } } /* 运行框架 Run Framework */ run(); |