Im trying to enter a .txt file into a postgres database using the code below.
This sql query works when I enter it directly in the database using pgAdminIII but in the php code i get a syntax error:
PHP Parse error: syntax error, unexpected T_STRING in D:\Apapub\public_html\databases\B13\upload_files.php on line 34
When I remove the ('') from around the text file like so:
$sql = 'COPY "public"."tblSedimentGrabEvent" FROM D:/Apapub/public_html/databases/B13/temp/grabevents.txt CSV';
I get a error from the sql side. any help will be appreciated, obviously I am new to the coding world.
Thanks
<?php
try {
$db = new PDO("pgsql:dbname=NAME;host=HOST","USER","PASS");
}
catch(PDOException $e) { echo $e->getMessage();
}
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Uploaded Successfully!<br>";
echo "File Name: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"]. "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"D:/Apapub/public_html/databases/B13/temp/" . $_FILES["file"]["name"]);
echo "Stored in: " . "D:\Apapub\public_html\databases\B13\temp" . $_FILES["file"]["name"]. "<br>";
}
}
$sql = 'COPY "public"."tblSedimentGrabEvent" FROM 'D:/Apapub/public_html/databases/B13/temp/grabevents.txt' CSV';
$resultC = $db->query($sql);
if (!$resultC){
echo ('The query did not succeed<BR>');
echo ($sql);
}
?>