Converting CSV Files to MySQL Insert Queries Using PHP
(Page 1 of 4 )
This article covers an important web application tool written in PHP that will let developers upload a CSV file and then convert that to MySQL insert queries.
This is particularly useful in a limited hosting environment where a user is restricted to importing or uploading an SQL file to the MySQL server. Converting the csv file (that contains the data) to MySQL insert queries makes it easy to transfer the data to MySQL server without doing any uploads (which are restricted).
Creation of the CSV file and the Initial Code
At the start of the script, it would be nice to declare the sessions (used for checking the security code submitted by the user versus the correct answer stored in a session variable) and turn off all PHP warnings that will be displayed to the web browser. This is not good to look at for the production server.
<?php
session_start();
error_reporting(0);
?>
Then the followed by the header portion HTML:
<HTML>
<HEAD>
<TITLE>Convert CSV to SQL insert queries tool</TITLE>