protected function _creatTable($sql, $dbname, $yl_manager, $yl_managerpw, $tblpre) { $installinfo = ''; $sql = str_replace("\r", '', $sql); $sql = $tblpre == 'ylmf_' ? $sql : str_replace('ylmf_', $tblpre, $sql); $sqlarray = array(); $sqlarray = explode(";\n", $sql); // ppr($sqlarray); app_db::select_db($dbname); foreach ($sqlarray as $key => $query) { if (empty($query)) { continue; } $query = trim(str_replace("\n", '', $query)); if ($query && strpos($query, 'CREATE TABLE') !== false) { $c_name = trim(substr($query, 27, strpos($query, '(') - 27)); $installinfo .= $this->_getLang('creat_table') . $c_name . ' ...' . $this->_getLang('success') . "\n"; $extra1 = trim(substr(strrchr($query, ')'), 1)); if (app_db::server_info() >= '4.1') { $extra2 = "ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ;"; // $extra2 = "ENGINE=MyISAM DEFAULT CHARSET=gbk COLLATE=gbk_chinese_ci ;"; } else { $extra2 = 'TYPE=MyISAM;'; } $query = str_replace($extra1, $extra2, $query); } app_db::query($query); } return $installinfo; }
/** * 查询记录数 * * @param string $table * @param string $condition * @return int */ public static function get_rows_num($table, $condition) { try { if (empty($table) || empty($condition)) { throw new Exception('查询记录数的表名,字段,条件不能为空', 444); } self::$sql = "SELECT count(*) AS total FROM {$table} WHERE {$condition}"; $result = self::query(self::$sql); $tmp = self::fetch_one(); return empty($tmp) ? false : $tmp['total']; } catch (Exception $e) { if (!defined('DEBUG_LEVEL') || !DEBUG_LEVEL) { } else { echo $e->getMessage(), '<br/>'; echo '<pre>', $e->getTraceAsString(), '</pre>'; echo '<strong>Query: </strong>[rows_num] ' . !empty(self::$sql) && self::$sql; } exit; } }