The previous answers have been horribly complex for the scope of this project. I want to take the $_POST result as a variable and insert it into a BYTEA field of a table.

$_SESSION['username'] = $username;
$file = $_POST["file"];

file is the file itself submitted from the form on the previous page

pg_prepare($conn, "register_user_info", 'INSERT INTO fileDB.assignment(pawprint, name, number, section, file) VALUES ($1, $2, $3, $4, $5)'); 
pg_execute($conn, "register_user_info", array($username, "1", "1", "1", $file));

I need to insert the file itself into the file column of my database. How can I make this happen?

  • 1
    You're using PHP with PostgreSQL - you're not using psql, the command-line client for PostgreSQL. – Craig Ringer Apr 15 '14 at 12:47
  • 4
    I'm voting to close this question as off-topic because it would be an SO question, but it is to late to migrate. – dezso Jul 1 '17 at 22:30

Your options are:

  • Use PDO, which properly supports binary parameters; or

  • Use pg_escape_bytea with string substitution into the query text.

See https://stackoverflow.com/q/17121791/398670 .

Not the answer you're looking for? Browse other questions tagged or ask your own question.