本文整理汇总了PHP中DataModel::multipleExecute方法的典型用法代码示例。如果您正苦于以下问题:PHP DataModel::multipleExecute方法的具体用法?PHP DataModel::multipleExecute怎么用?PHP DataModel::multipleExecute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataModel
的用法示例。
在下文中一共展示了DataModel::multipleExecute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
//.........这里部分代码省略.........
$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']])];
$listRow[$attributesFlip['SitUpsGrade']] = $otherArr[trim($listRow[$attributesFlip['SitUpsGrade']])];
$listRow[$attributesFlip['_1000mGrade']] = $otherArr[trim($listRow[$attributesFlip['_1000mGrade']])];
$listRow[$attributesFlip['_800mGrade']] = $otherArr[trim($listRow[$attributesFlip['_800mGrade']])];
$listRow[$attributesFlip['_400mGrade']] = $otherArr[trim($listRow[$attributesFlip['_400mGrade']])];
$listRow[$attributesFlip['ropeSkippingGrade']] = $otherArr[trim($listRow[$attributesFlip['ropeSkippingGrade']])];
$listRow[$attributesFlip['SumUpGrade']] = $otherArr[trim($listRow[$attributesFlip['SumUpGrade']])];
$user->stuId = trim($listRow[$attributesFlip['stuId']]);
$user->password = sha1(substr(trim($listRow[$attributesFlip['stuId']]), -6));
$sqlParams[] = array('userFlag' => true, 'sql' => $user->create(true), 'sheetName' => $currentSheet->getTitle(), 'row' => $listRow['row']);
foreach ($attributes as $key => $attr) {
$listRow[$key] = str_replace(' ', '', trim($listRow[$key]));
$model->{$attr} = $listRow[$key];
if (empty($model->{$attr})) {
$model->{$attr} = 0;
}
}
// print_r($model);
$model->stuName = mb_substr($model->stuName, mb_strlen($model->stuName) - 2);
$model->stuName = "*" . $model->stuName;
//将 姓氏 转化成*
$sqlParams[] = array('userFlag' => false, 'sql' => $model->create(true), 'sheetName' => $currentSheet->getTitle(), 'row' => $listRow['row']);
unset($listRow);
//每个页面每1000行提交一次
if ($row % 1000 == 0 || $row == $highestRow) {
$model->multipleExecute($sqlParams, false, $errorRowArr, $affectedRows);
unset($sqlParams);
if (count($errorRowArr) && !empty($errorRowArr[0]['sheetName'])) {
$totalInsertErrorArr[] = $errorRowArr;
unset($errorRowArr);
}
}
}
//记录数据不完整的行
if (count($emptyErrorArr)) {
$totalEmptyErrorArr[] = $emptyErrorArr;
$emptyErrorArr = array();
}
}
/*if (count($totalEmptyErrorArr)) {
echo '有' . count($totalEmptyErrorArr) . '条数据不完整';
print_r($totalEmptyErrorArr);
}
if (count($totalInsertErrorArr)) {
echo '有' . count($totalInsertErrorArr) . '条数据插入失败';
var_dump($totalInsertErrorArr);
}*/
}
$currentYear = date('Y');
$yearArr = array($currentYear - 1 . '-' . $currentYear, $currentYear . '-' . ($currentYear + 1), $currentYear - 2 . '-' . ($currentYear - 1));
$this->render('data/upload', array('yearArr' => $yearArr, 'totalEmptyErrorArr' => $totalEmptyErrorArr, 'totalInsertErrorArr' => $totalInsertErrorArr, 'post' => isset($_POST['send']) ? true : false, 'affectedRows' => $affectedRows, 'usedTime' => sprintf("%0.2f", microtime(true) - $beginTime)));
}