www/includes/db_recipes.php

changeset 50
6d94167c2697
parent 49
4d27a7fb1265
child 51
7224109adfe1
equal deleted inserted replaced
49:4d27a7fb1265 50:6d94167c2697
1 <?php 1 <?php
2 2
3 //require($_SERVER['DOCUMENT_ROOT']."/config.php"); 3 require($_SERVER['DOCUMENT_ROOT']."/config.php");
4 //require($_SERVER['DOCUMENT_ROOT']."/version.php"); 4 require($_SERVER['DOCUMENT_ROOT']."/version.php");
5 require("../config.php"); 5 //require("../config.php");
6 require("../version.php"); 6 //require("../version.php");
7 7
8 8
9 #Connect to the database 9 #Connect to the database
10 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); 10 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
11 if (! $connect) { 11 if (! $connect) {
12 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); 12 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
13 } 13 }
14
15 $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
16 $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
14 17
15 // get data and store in a json array 18 // get data and store in a json array
16 $query = "SELECT * FROM recipes ORDER BY style_guide,style_letter,style_name,name"; 19 $query = "SELECT * FROM recipes ORDER BY style_guide,style_letter,style_name,name";
17 if (isset($_GET['insert'])) { 20 if (isset($_GET['insert'])) {
18 // // INSERT COMMAND 21 // // INSERT COMMAND
63 if ($comma) { 66 if ($comma) {
64 $recipes .= ','; 67 $recipes .= ',';
65 } 68 }
66 $comma = TRUE; 69 $comma = TRUE;
67 $recipes .= '{"record":' . $row['record']; 70 $recipes .= '{"record":' . $row['record'];
68 $recipes .= ',"style_guide":"' . $row['style_guide']; 71 $recipes .= ',"style_guide":"' . str_replace($escapers, $replacements, $row['style_guide']);
69 $recipes .= '","style_letter":"' . $row['style_letter']; 72 $recipes .= '","style_letter":"' . str_replace($escapers, $replacements, $row['style_letter']);
70 $recipes .= '","style_name":"' . $row['style_name']; 73 $recipes .= '","style_name":"' . str_replace($escapers, $replacements, $row['style_name']);
71 $recipes .= '","name":"' . $row['name']; 74 $recipes .= '","name":"' . str_replace($escapers, $replacements, $row['name']);
72 $recipes .= '","notes":"' . $row['notes']; 75 $recipes .= '","notes":"' . str_replace($escapers, $replacements, $row['notes']);
73 $recipes .= '","type":"' . $row['type']; 76 $recipes .= '","type":"' . $row['type'];
74 $recipes .= '","batch_size":' . floatval($row['batch_size']); 77 $recipes .= '","batch_size":' . floatval($row['batch_size']);
75 $recipes .= ',"boil_time":' . floatval($row['boil_time']); 78 $recipes .= ',"boil_time":' . floatval($row['boil_time']);
76 $recipes .= ',"efficiency":' . floatval($row['efficiency']); 79 $recipes .= ',"efficiency":' . floatval($row['efficiency']);
77 $recipes .= ',"est_og":' . floatval($row['est_og']); 80 $recipes .= ',"est_og":' . floatval($row['est_og']);

mercurial