I'm a MySQL newbie finishing up a chunk of code central to my webapp. The code imports a CSV file (locally), that is generated and cleaned up by FileMaker and leaves it be.
Given this is will go to production at some point soon (and probably be a database under 500mb ), I would love to know if there is any better error checking /catching that I could do to possibly prevent issues down the road or be alerted to my server setup. I've read things about temp logs, etc. and my MySQL administration isn't up to snuff yet.
The very basic code is:
$m = mysql_connect('localhost', 'mytable', 'mypassword');
$db = 'mydb';
mysql_select_db($db) or die("Import Error - Couldn't select database: " . mysql_error());
$sql = 'load data local infile "inventory.csv"
into table ibl_account_details_temp fields terminated by ","
optionally enclosed by "\""
lines terminated by "\r"
(store_id, SKU, account, item_number, brand, description, size, category, price, qty, fees)
';
echo mysql_query($sql) or die(myqsl_error());
PS EDIT: I would also love to know if this method of import is open to SQL injection?
LOAD DATA INFILE
, since MySQL isn't executing the contents of the CSV file, it's just parsing it as CSV. Of course that says nothing about the risk of a second order attack, but as long as every query that takes input (including input from a query result) uses parameterization you should be safe. For that reason (amongst others) you should, use mysqli or PDO to access mysql instead of the mysql_* functions.LOAD DATA INFILE
to import CSV, that's what it's for.