Last active
December 19, 2015 06:11
-
-
Save vvikramjhu/5c5b9de76385f04b26bd to your computer and use it in GitHub Desktop.
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
// How do change $key and $value below so they can be used as parametric inserts into the db ? | |
<?php | |
$json = file_get_contents('sampleData.json'); | |
$obj = json_decode($json, true); | |
// Connect to Db | |
$username = "root"; | |
$password = "ernest"; | |
$database_name = "test"; | |
$host = "localhost"; | |
$port = "3306"; | |
if($host == ""){ | |
$host = "127.0.0.1"; | |
} | |
if($port == ""){ | |
$port = "3306"; | |
} | |
$port = intval($port); | |
$mysqli = new mysqli($host, $username, $password, $database_name, $port); | |
if ($mysqli->connect_errno) { | |
$error_string = sprintf("Connect failed: %s\n", $mysqli->connect_error); | |
} | |
/* insert data into DB */ | |
foreach($obj as $key => $value){ | |
var_dump($value); | |
$sql = "INSERT into test.dashboard(demo_variable, demo_hard_coded_values) values(?, ?) "; | |
$stmt = $mysqli->prepare($sql); | |
$stmt->bind_param('ss', $key, $value); | |
$stmt->execute(); | |
} | |
$stmt->close(); |
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
array(6) { [0]=> string(7) "$47,171" [1]=> string(76) "1300, 1877, 2500, 2577, 2000, 2100, 3000, 2700, 3631, 2471, 2700, 3631, 2471" | |
[2]=> string(46) " 45%" [3]=> string(49) "110,150,300,130,400,240,220,310,220,300, 270, 210" [4]=> string(45) " 2447" | |
[5]=> string(49) "110,150,300,130,400,240,220,310,220,300, 270, 210" } | |
Fatal error: Call to a member function bind_param() on a non-object in | |
O:\Airius misc Sep and onwards\dashboard\SmartAdmin\DEVELOPER\AJAX_version\data\fillStatic.php on line 34 |
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
{ | |
"sparks": ["$47,171", "1300, 1877, 2500, 2577, 2000, 2100, 3000, 2700, 3631, 2471, 2700, 3631, 2471", | |
"<i class=\"fa fa-arrow-circle-up\"></i> 45%", "110,150,300,130,400,240,220,310,220,300, 270, 210", | |
"<i class=\"fa fa-shopping-cart\"></i> 2447", "110,150,300,130,400,240,220,310,220,300, 270, 210"], | |
"MyTasks": ["130/200", "width: 65%;"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment