hi i want to insert some data from a parsed json to a table, but when i do it, it doesn't work, it returns 0 rows, what am i missing? i'm new yet with this "mysqli".. i have more than 25000 rows to insert to the table. thx
$mysqli = mysqli_connect('localhost', 'root', '', '');
$allData = $dataSource->getAllData();
foreach ($allData as $key => $value) {
$query = 'INSERT INTO `table`(`data_id`, `name`) VALUES (' . $value['data_id'] . ', ' . $value['name'] . ')';
$result = mysqli_query($mysqli, $query);
}
it works now, it inserted all the object data, the code that i made thx to replies is something like this:
$mysqli = mysqli_connect('localhost', 'root', '', '') or die(mysqli_connect_error());
if (!$mysqli) {
die('Could not connect: ' . mysqli_error());
}
$allData = $dataSource->getAllData();
foreach ($allData as $key => $value) {
$query = mysqli_prepare($mysqli, "INSERT INTO `table`(`data_id`, `name`) VALUES (?, ?)");
mysqli_stmt_bind_param($query, 'is', $value['data_id'], $value['name']);
mysqli_stmt_execute($query);
mysqli_stmt_close($query);
}
hope everything is ok here, i'm new in this mysqli and i need a lot of practice with programming