Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Initialize variable for database credentials
- $dbhost = 'localhost';
- $dbuser = 'root';
- $dbpass = '';
- $dbname = 'history';
- //Create database connection
- $dblink = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
- //Check connection was successful
- if ($dblink->connect_errno) {
- printf("Failed to connect to database");
- exit();
- }
- //Fetch 3 rows from actor table
- $result = $dblink->query("SELECT * FROM main");
- //Initialize array variable
- $dbdata = array();
- //Fetch into associative array
- while ( $row = $result->fetch_assoc()) {
- $row = array_map('utf8_encode', $row); //conversione per caratteri speciali èùòà
- $dbdata[]=$row;
- //debug_zval_dump($dbdata);
- }
- //Print array in JSON format
- //echo json_encode($dbdata);
- //echo "<pre>";
- //echo json_encode($dbdata, JSON_PRETTY_PRINT);
- //echo "</pre>";
- $myFile = "js_history_test.json";
- $fh = fopen($myFile, 'w') or die("can't open file");
- $stringData = json_encode($dbdata);
- fwrite($fh, $stringData);
- fclose($fh);
- //START FILE
- $prepend = "
- [
- {
- \"id\":\"js_history\",
- \"title\":\"ROMAN EMPIRE\",
- \"description\":\"<p>descrizione</p>\",
- \"focus_date\":\"-753-01-01 12:00:00\",
- \"initial_zoom\":\"39\",
- \"image_lane_height\":50,
- \"events\":
- ";
- $file = 'js_history_test.json';
- $fileContents = file_get_contents($file);
- echo $fileContents;
- //MIDDLE FILE
- file_put_contents($file, $prepend . $fileContents);
- //END FILE
- $myfile = fopen("js_history_test.json", "a") or die("Unable to open file!");
- $txt = "}]";
- fwrite($myfile, "\n". $txt);
- fclose($myfile);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement