Skip to content

Commit 66e7e59

Browse files
committed
Use prepared statement for table insertion
1 parent 68fd7c0 commit 66e7e59

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tools/Parser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,9 @@ function fileToTempTable(string $tableName, $file, $fields, $fileSize, string $p
238238
}
239239

240240
// Build a query
241-
$insQuery = "INSERT INTO {$tableName} VALUES('" . implode("', '", $lineSplit) . "')";
242-
if (!mysqli_query($this->dbConn, $insQuery)) {
241+
$stmt = $this->dbConn->prepare("INSERT INTO {$tableName} VALUES(" . implode(", ", array_fill(0, $fields, "?")) . ")");
242+
$stmt->bind_param(str_repeat("s", $fields), ...$lineSplit);
243+
if (!$stmt->execute()) {
243244
echo("*** Failed to insert {$tableName}\n");
244245
echo(" " . mysqli_error($this->dbConn) . "\n");
245246
continue;

0 commit comments

Comments
 (0)