本文整理汇总了PHP中DataModel::tableExist方法的典型用法代码示例。如果您正苦于以下问题:PHP DataModel::tableExist方法的具体用法?PHP DataModel::tableExist怎么用?PHP DataModel::tableExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataModel
的用法示例。
在下文中一共展示了DataModel::tableExist方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
public function upload()
{
$attrModel = new AttributesModel();
$configArr = (array) $attrModel->getConfig();
if ($configArr['beginRow'] == 0) {
Tool::alertBackNoRefresh('请先设置上传文件的数据格式:)');
return;
}
$allAttr = $attrModel->getAttributes();
$allAttrArray = array();
foreach ($allAttr as $attr) {
$allAttrArray[] = $attr->attributeName;
}
$attributes = array_values(array_slice($configArr, 4, 57));
$attributesFlip = array_flip($attributes);
/*print_r($attributesFlip);
echo '<hr/>';*/
$sheetNumArr = explode('-', $configArr['dataSheetNum']);
foreach ($sheetNumArr as $key => &$sheetNum) {
if (trim($sheetNum)) {
$sheetNum = trim($sheetNum) - 1;
} else {
unset($sheetNumArr[$key]);
}
}
if (isset($_POST['send'])) {
$beginTime = microtime(true);
$fileName = $_FILES['excel']['name'];
$explodeArr = explode('.', $fileName);
$extensionName = $explodeArr[count($explodeArr) - 1];
$inputFileName = $_FILES['excel']['tmp_name'];
require '../Extension/PHPExcel_1.8.0/Classes/PHPExcel.php';
require '../Extension/PHPExcel_1.8.0/Classes/PHPExcel/Writer/Excel2007.php';
require '../Extension/PHPExcel_1.8.0/Classes/PHPExcel/Writer/Excel5.php';
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
if ($inputFileType != 'Excel2007' && $inputFileType != 'Excel5') {
Tool::alertBackNoRefresh('上传文件格式不正确:(');
return;
}
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$PHPExcel = $objReader->load($inputFileName);
//根据自己的数据表的大小修改
$arr = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13, 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26, 'AA' => 27, 'AB' => 28, 'AC' => 29, 'AD' => 30, 'AE' => 31, 'AF' => 32, 'AG' => 33, 'AH' => 34, 'AI' => 35, 'AJ' => 36, 'AK' => 37, 'AL' => 38, 'AM' => 39, 'AN' => 40, 'AO' => 41, 'AP' => 42, 'AQ' => 43, 'AR' => 44, 'AS' => '45', 'AT' => 46, 'AU' => 47, 'AV' => 48, 'AW' => 49, 'AX' => 50, 'AY' => 51, 'AZ' => 52, 'BA' => 53, 'BB' => 54, 'BC' => 55, 'BD' => 56, 'BE' => 57);
$sexArr = array('男' => 1, '女' => 0);
$BMIArr = array('肥胖' => 0, '超重' => 1, '低体重' => 2, '正常' => 3);
$otherArr = array('不及格' => 0, '及格' => 1, '良好' => 2, '优秀' => 3);
$year = $_POST['year'];
$year = str_replace('-', '_', $year);
$tableName = 'tice_data_' . $year;
$model = new DataModel();
$model->dbName = 'tice';
$model->tableName = $tableName;
if (!$model->tableExist()) {
$model->createTable();
}
$model = new DataModel();
foreach ($allAttrArray as $attr) {
$model->{$attr} = 0;
}
$user = new UserModel();
$totalEmptyErrorArr = array();
$totalInsertErrorArr = array();
//检查插入失败数据的二维数组
$emptyErrorArr = array();
//检查不完整的数据的二维数组
$sqlParams = array();
$affectedRows = 0;
foreach ($sheetNumArr as $i) {
$currentSheet = $PHPExcel->getSheet($i);
//获得工作表,从0开始
$highestRow = $currentSheet->getHighestRow();
// 取得总行数
$highestColumn = $currentSheet->getHighestColumn();
//取得总列数 比如 ‘AJ'列这样子
// echo $currentSheet->getTitle() . ' ' . $highestRow . '<br/>'; // 得到当前工作表的名字
//读取一个工作表的数据 每次读取一行,再在行中循环每列的数值
for ($row = $configArr['beginRow']; $row <= $highestRow; $row++) {
$listRow = array();
for ($column = self::BEGIN_COL; $column <= $arr[$highestColumn]; $column++) {
$val = $currentSheet->getCellByColumnAndRow($column, $row)->getValue();
$listRow[] = $val;
$listRow['row'] = $row;
}
// print_r($listRow);
//检查数据的完整性
if (!self::checkDataComplete($configArr['schoolType'], $listRow, $attributesFlip)) {
$empty = array();
$empty['sheetName'] = $currentSheet->getTitle();
$empty['row'] = $row;
$emptyErrorArr[] = $empty;
unset($empty);
}
$model->tableName = $tableName;
$listRow[$attributesFlip['sex']] = $sexArr[trim($listRow[$attributesFlip['sex']])];
$listRow[$attributesFlip['BMIGrade']] = $BMIArr[trim($listRow[$attributesFlip['BMIGrade']])];
$listRow[$attributesFlip['FVCGrade']] = $otherArr[trim($listRow[$attributesFlip['FVCGrade']])];
$listRow[$attributesFlip['_50mGrade']] = $otherArr[trim($listRow[$attributesFlip['_50mGrade']])];
$listRow[$attributesFlip['SARGrade']] = $otherArr[trim($listRow[$attributesFlip['SARGrade']])];
$listRow[$attributesFlip['SLJGrade']] = $otherArr[trim($listRow[$attributesFlip['SLJGrade']])];
$listRow[$attributesFlip['ChinUpGrade']] = $otherArr[trim($listRow[$attributesFlip['ChinUpGrade']])];
//.........这里部分代码省略.........