I need to load data onto a sql db I have searched and got examples and used them to get this far.
If I run this part I am able to connect to the db.
[php]<?php
$mysqli = new mysqli(‘localhost’,‘username’,‘password’,‘DB_Name’);
/* check connection */
if (mysqli_connect_errno()) {
printf(“Connect failed: %s\n”, mysqli_connect_error());
exit();
};
?>[/php]
this is the full output of the code, It shows a echo but nothing is shown on the page a blank page is displayed so im not sure where my error is.
1)
[php]<?php
$mysqli = new mysqli(‘localhost’,‘username’,‘password’,‘DB_Name’);
/* check connection */
if (mysqli_connect_errno()) {
printf(“Connect failed: %s\n”, mysqli_connect_error());
exit();
}
$sql = “LOAD DATA LOCAL INFILE ‘Data-Bin.CSV’
INTO TABLE Stats_Day
FIELDS TERMINATED BY ‘,’ ENCLOSED BY '”’
LINES TERMINATED BY ‘\n’
IGNORE 1 ROWS
(@txdate, department, code, descript, QTY, Total)
SET txdate = STR_TO_DATE(@txdate, ‘%Y/%m/%d’);
//Try to execute query (not stmt) and catch mysqli error from engine and php error
if (!($stmt = $mysqli->query($sql))) {
echo “\nQuery execute failed: ERRNO: (” . $mysqli->errno . ") " . $mysqli->error;
};
?>[/php]
2)
Is there a way that I could ad this to the bunch?
DELETE Stats_Day
;
this is a script that needs to import the stats daily so I need to clear the table data and then load the new data?
Im new to this and all help would be very much appreciated.