Hi all. I'm trying to get the following code to execute in order to load data into a table.
$database = $_POST["dbase"];
echo "<br />Database is $database<br />";
$targetTable = $_POST["targetTable"];
$connection = mysql_connect("localhost","cart","cecs383") or die("Database server connection attempt failed.");
mysql_select_db($database, $connection) or die("Failed to select database: $database");
$query = "LOAD DATA LOCAL INFILE '$dumpData' INTO TABLE '$targetTable'";
mysql_query($query, $connection) or sqlError("Failed to load data in $dumpData into table $targetTable.");
echo "$query Executed successfully";
Here is the function sqlError():
function sqlError($dieString) {
echo "<br />Error function under here<br />";
echo "<br>" . mysql_errno() . ": " .
msyql_error(). "<br>";
die($dieString);
}
This is the result I get from running that query in the php:
1064: You have an error in your SQL syntax near ''category'' at line 1
Failed to load data in /home/shares/batchdata/test/category.csv into table category.
When I run this query from the mysql monitor, replacing $dumpData with "/home/shares/batchdata/test/category.csv" and $targetTable with "category" I get:
Query OK, 3 rows affected (0.01 sec)
Records: 3 Deleted: 0 Skipped: 0 Warnings: 3
The sinqle quotes around string variables in the query have proved necessary in other queries I've run in php's, before they would run. So after examining, I can't figure out why this query is producing an error. Can anyone provide any insights?