This is in reference to multiple posts (like this one) but I canot figure out how it works. I am trying to insert multiple rows at once with a sql statement. Here is my code with what I found in previous posts:
$mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno(). ') ' . mysqli_connect_error());
}
$body = file_get_contents('php://input');
$jsonArray = json_decode($body, true);
// Test
$results = print_r($jsonArray, true);
file_put_contents('filename.txt', print_r($results, true)); // write file to see formatting key/value
$sql = array();
foreach ($jsonArray as $row) {
$sql[] = '("'.mysql_real_escape_string($row['text']).'", '.$row['category_id'].')';
}
$mysqli->query('INSERT INTO tbl_syncListLite (text, category) VALUES '.implode(',', $sql));
if ($mysqli === TRUE) {
$response = array('status' => '1');
} else {
$response = array('status' => '0');
}
echo json_encode($response);
$mysqli->close();
?>
I really do not understand this part:
$sql[] = '("'.mysql_real_escape_string($row['text']).'", '.$row['category_id'].')';
$mysqli->query('INSERT INTO tbl_syncListLite (text, category) VALUES '.implode(',', $sql));
...and especially if 'text' and 'category id' refer to specific words or if I have to replace them with my fieldnames. Moreover I do not understand how it can manage multiples fields and if some are integers vale and so one (datetime,...).
If anybody could help me, it would be really appreciated.