예제 #1
0
function uploadFiletoDB($UserFileName)
{
    $TransactionArray = array();
    $TblName = TableName;
    $FileName = $_FILES[$UserFileName]['name'];
    $FileServerName = $_FILES[$UserFileName]['tmp_name'];
    $CSVFIle = 'transactionTable.csv';
    $CSVDelimiter = ';';
    $ValidRecordswrited = 0;
    $InvalidRecords = 0;
    if (getFileExtension($FileName) == 'xlsx') {
        convertXLStoCSV($FileServerName, $CSVFIle);
        $CSVDelimiter = ',';
    } else {
        $CSVFIle = $FileServerName;
    }
    $TransactionArray = csv_to_array($CSVFIle, $CSVDelimiter);
    if (sizeof($TransactionArray) > 100000) {
        echo '<br>';
        echo "Error - file rows cont is to much";
        return false;
    }
    $Connection = mysql_connect(ServerName, UserName, Password);
    $db_selected = mysql_select_db(DBName, $Connection);
    if (!$Connection) {
        die("Connection failed: " . mysql_error());
    }
    foreach ($TransactionArray as $Line) {
        if (checkTransactionRecord($Line)) {
            $Request = "INSERT INTO {$TblName}(`Account`, `Description`, `CurrencyCode`, `Ammount`) VALUES ('{$Line['Account']}','{$Line['Description']}','{$Line['CurrencyCode']}',{$Line['Amount']})";
            $result = mysql_query($Request);
            if (!$result) {
                echo 'Query error: ' . mysql_error();
            } else {
                $ValidRecordswrited++;
            }
        } else {
            $InvalidRecords++;
        }
    }
    mysql_close($Connection);
    echo '<br> <br>';
    echo "Valid records writed to DataBase: {$ValidRecordswrited}";
    echo '<br>';
    echo "Invalid records count: {$InvalidRecords}";
}
예제 #2
0
function updateRecord()
{
    $Record = array(id => $_POST["id"], Account => $_POST["Account"], Description => $_POST["Description"], CurrencyCode => $_POST["CurrencyCode"], Ammount => $_POST["Ammount"]);
    if (!checkTransactionRecord($Record)) {
        return;
    }
    $TblName = TableName;
    $Connection = mysql_connect(ServerName, UserName, Password);
    $db_selected = mysql_select_db(DBName, $Connection);
    if (!$Connection) {
        die("DataBase connection failed: " . mysql_error());
    }
    $Request = "UPDATE {$TblName} SET Account='{$Record["Account"]}', Description='{$Record["Description"]}', CurrencyCode='{$Record["CurrencyCode"]}', Ammount='{$Record["Ammount"]}' WHERE  id={$Record["id"]}";
    $result = mysql_query($Request);
    if ($result) {
        echo "Record was updated";
    } else {
        echo 'Query error: ' . mysql_error();
        echo '<br>';
        echo $Request;
        echo '<br>';
    }
    mysql_close($Connection);
}