Why does this $pdo function import a CSV alphabetically into the database table?

1 day ago 1
ARTICLE AD BOX

Why is my CSV file imported into the database alphabetically by the first column product_key? Rather than imported simply line by line, from first line in the CSV to the last line?

My CSV is not sorted by product_key, but after import, the rows are sorted alphabetically in my_table, as seen in PHPMyAdmin. The table is InnoDB.

I don't use ASC or DESC in $pdo->prepare

I'd like to figure thus out because on a page I display the data from the table below the csv file upload form, and I want the data to appear the same as the uploaded file.

Any ideas?

PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]); try { $pdo->exec("TRUNCATE TABLE my_table"); $file = fopen($fileTmpPath, "r"); // Start transaction $pdo->beginTransaction(); $stmt = $pdo->prepare(" INSERT INTO my_table (product_key, ID_key, value) VALUES (?, ?, ?) "); // Skip header fgetcsv($file); while (($row = fgetcsv($file, 1000, ",")) !== FALSE) { if (count($row) < 3) continue; $stmt->execute([$row[0], $row[1], $row[2]]); } fclose($file); $pdo->commit();
Read Entire Article