<?php
/*
brief - 엑셀 읽어서 DB와 sync 맞추는 스크립트
author - ila
date - 2022-08-03
*/
ini_set('memory_limit','-1');
//error_reporting(~E_ALL & ~E_NOTICE);
require_once("/home/ila/common/conf/dbconn.conf.php");
require_once ('/home/ila/public_html/application/libraries/PHPExcel.php');
$conn_cms->query("set names utf8");
$filepath = "list.xlsx";
$filetype = PHPExcel_IOFactory::identify($filepath);
$reader = PHPExcel_IOFactory::createReader($filetype);
$php_excel = $reader->load($filepath);
$sheet = $php_excel->getSheet(0); // 첫번째 시트
$maxRow = $sheet->getHighestRow(); // 마지막 라인
$maxColumn = $sheet->getHighestColumn(); // 마지막 칼럼
$target = "A"."1".":"."$maxColumn"."$maxRow";
$lines = $sheet->rangeToArray($target, NULL, TRUE, FALSE);
$s = 1;
// 라인수 만큼 루프
foreach ($lines as $key => $line) {
$col = 0;
$item = array(
"A"=>$line[$col++], // 첫번째 칼럼
"B"=>$line[$col++], // 두번쨰 칼럼
);
$barcode_no = str_replace("'","",$item["A"]);
$usedate = $item["B"];
$usedate = date( 'Y-m-d', strtotime( $usedate ) );
print_r($barcode_no.",". $usedate."\n");
echo $qry = "select barcode_no, usedate, state from table where barcode_no = '{$barcode_no}' and state in ('예약완료') limit $s";
$res = $conn_cms3->query($qry);
while($row = $res->fetch_object()){
$rprsBarno = $row->barcode_no;
$rprsUsedate = $row->usedate;
$rprsState = $row->state;
print_r("\n".$rprsBarno."-".$rprsUsedate."-".$rprsState."\n");
$uqry = "update db.table set usedate = '$usedate' where barcode_no = '$barcode_no' and state in ('예약완료') limit $s";
$ures = $conn_cms3->query($uqry);
print_r("성공 : ".$ures."\n ================== \n");
echo $sqry = "select barcode_no, usedate, state from db.table where barcode_no = '{$barcode_no}' and state in ('예약완료') limit $s";
$srow = $conn_cms3->query($sqry)->fetch_object();
$rprsBarno2 = $row->barcode_no;
$rprsUsedate2 = $row->usedate;
$rprsState2 = $row->state;
print_r("변경완료 : ".$rprsBarno2."-".$rprsUsedate2."-".$rprsState2."\n");
echo "\n ================== \n";
}
}
댓글