function addFileIntoDB($file, $table) { $reussi = 0; $echoue = 0; $ds = CSQLDataSource::get("ccamV2"); $handle = fopen($file, "r"); $values = array(); $batch = 50; // Ne pas utiliser fgetcsv, qui refuse de prendre en compte les caractères en majusucules accentués (et d'autres caractères spéciaux) while ($line = fgets($handle)) { $line = str_replace("'", "\\'", $line); $values[] = explode("|", $line); if (count($values) == $batch) { insertValues($ds, $table, $values, $echoue, $reussi); $values = array(); } } if (count($values)) { insertValues($ds, $table, $values, $echoue, $reussi); } CAppUI::stepAjax("Import du fichier {$file} dans la table {$table} : {$reussi} lignes ajoutée(s), {$echoue} échouée(s)", UI_MSG_OK); fclose($handle); }
function getLiveValues() { exec('sudo node /root/node_modules/flower-power/atlantis.js', $output); while (count($output) == 0) { exec('sudo node /root/node_modules/flower-power/atlantis.js', $output); } for ($i = 0; $i < count($output); $i++) { $line = explode('=', $output[$i]); if ($line[0] == 'id') { $batteryArr = explode('=', $output[$i + 1]); $lightArr = explode('=', $output[$i + 3]); $conductivityArr = explode('=', $output[$i + 4]); $soilTemperatureArr = explode('=', $output[$i + 5]); $airTemperatureArr = explode('=', $output[$i + 6]); $moistureArr = explode('=', $output[$i + 7]); insertValues($line[1], $batteryArr[1], $lightArr[1], $conductivityArr[1], $soilTemperatureArr[1], $airTemperatureArr[1], $moistureArr[1]); } } return 200; }
$selectdb = mysqli_select_db($conn, "learnphp"); //this is procedural way and returns boolean value if ($selectdb) { //database is present createTable($conn); //check table if exists or create new table insertValues($conn); //Adding values to database } else { //database is not present so create one $sql = "CREATE DATABASE learnphp"; $check = mysqli_query($conn, $sql); if ($check == TRUE) { //database created echo "Database created successfully<br/>"; $selectdb = mysqli_select_db($conn, "learnphp"); //Select database query imp to set default database for operations if ($selectdb) { //database selected createTable($conn); //check table if exists or create new table insertValues($conn); //Adding values to database } else { echo "error selecting database..error is : " . mysqli_error($conn); } } else { echo "Error creating database: " . mysqli_error($conn); } } mysqli_close($conn);
if (!$handler) { throw new Exception('Невозможно открыть файл.'); } $connection = new mysqli($config['host'], $config['db_user'], $config['db_password'], $config['db_name'], $config['port']); if (!$connection) { throw new Exception('Невозможно установить связь с БД.'); } $connection->query("DELETE FROM rest_data"); while ($result = fgetcsv($handler, null, ';')) { if (count($result) != 8) { continue; } if (!is_numeric($result[0])) { continue; } if (!insertValues($result, $connection)) { echo $twig->render('upload.html', array('status' => 'Ошибка при обработке файла.')); exit; } } echo $twig->render('upload.html', array('status' => 'Файл успешно загружен.')); } catch (Exception $e) { echo $e->getMessage(); } } else { echo $twig->render('upload.html', array('status' => 'Неверный формат файла.')); } } else { echo $twig->render('upload.html'); } });
\t\t\t// Pop back onto browser thread and call event handler. \t\t\t// Have to use nested function here instead of GM_hitch because \t\t\t// otherwise details[event].apply can point to window.setTimeout, which \t\t\t// can be abused to get increased priveledges. \t\t\tnew XPCNativeWrapper(unsafeContentWin, "setTimeout()") \t\t\t\t.setTimeout(function(){details[event](responseState);}, 0); \t\t} \t} } EOF; $xpi['content/' . $data['shortname'] . '.js'] = $_POST['script'] . "\n"; //walk over the xpi array, and replace all our "variables" unset($_POST['script']); //for efficiency foreach (array_keys($xpi) as $k) { $xpi[$k] = insertValues($xpi[$k], $data); } $zip = new CreateZip(); $zip->addDirectory('chrome/'); foreach ($xpi as $k => $v) { $zip->addFile($v, $k); } $zip->forceDownload($data['shortname']); print_r($_FILES['script']); } else { ?> <!doctype html public '-//w3c//dtd xhtml 1.1//en' 'http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd'> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'> <head> <meta http-equiv='content-type' content='text/html; charset=UTF-8' /> <title>User Script Compiler</title>
case "4": $amount = 78.59999999999999; break; case "5": $amount = 500; break; case "6": $amount = 898; break; case "7": $amount = 1500; break; case "8": $amount = $_POST["other"]; break; default: echo "Error"; } if (empty($_POST["sponsor"])) { echo "Please enter your name, we will not share it with anyone."; exit; } else { $sponsor = $_POST["sponsor"]; } $today = date("m/d/Y"); insertValues($sponsor, $amount, $today); //showData(); ?> <footer> <address>Created in between 2014-10-13 and 2014-10-31. <br />Written by <a href='mailto:tchen@scu.edu'>Travis Chen</a> and <a href='mailto:adiaztostado@scu.edu'>Alberto Diaz</a>.</address> </footer>