Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
timerec3public/zeitenrun.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
53 lines (44 sloc)
1.98 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
if(php_sapi_name() != "cli"){ | |
echo "<h3>keine Rechte, dieses Script aus dem Web auszuführen!</h3>"; | |
exit; | |
} | |
//Dieses Script dient der Evaluierung und kopiert immer die Zeiten aus der alten DB in die neue. | |
//kopiert nur daten von gestern und heute. | |
//kann nur als root und nur als root SQL User laufen. | |
$dbc = new mysqli("db2.rz-berlin.mpg.de", "root", "t9lisker", "timerec3"); | |
if ($dbc->connect_errno) { | |
echo "Failed to connect to MySQL: (" . $dbc->connect_errno . ") " . $dbc->connect_error; | |
exit; | |
} | |
$insertselect = "insert into timerec3.zeit (zeit_ID, maID, datumzeit, status, note, timestamp, userid) | |
select mz_ID, maID, datumzeit, status, mz_bem, timestamp, userid from zeit.MA_Zeit | |
where date(datumzeit) > subdate(current_date, 1) and zt_ID = 0 | |
on duplicate key update zeit_ID = values(zeit_ID), maID = values(maID), datumzeit = values(datumzeit), status = values(status), | |
note = values(note), timestamp = values(timestamp), userid = values(userid);"; | |
$dbc->query($insertselect); | |
if($dbc->error){ | |
echo "FEHLER: \n"; | |
echo $dbc->error; | |
echo "\n"; | |
echo "SQL QUERY: ".$insertselect."\n"; | |
}else{ | |
echo "ERFOLG: ".$dbc->affected_rows." Zeilen wurden übertragen.\n"; | |
} | |
$transform = "select m2.maID as oldmaID, m.maID from timerec3.mitarbeiter m join zeit.Mitarbeiter m2 on m.userid = m2.userid;"; | |
$transformdata = $dbc->query($transform); | |
foreach($transformdata as $data){ | |
$updatemaIDs = "update timerec3.zeit set maID = $data[maID] where maID = '$data[oldmaID]';"; | |
$dbc->query($updatemaIDs); | |
if($dbc->error){ | |
echo "FEHLER: \n"; | |
echo $dbc->error; | |
echo "\n"; | |
echo "SQL QUERY: ".$updatemaIDs."\n"; | |
}else{ | |
echo "ERFOLG: ".$dbc->affected_rows." Zeilen wurden bearbeitet.\n"; | |
} | |
} | |
$dbc->close(); | |
?> |