From the point of view of PHP, there are at least two ways to avoid the error message, one that is "quick and dirty", and the other one more complicated but clean.
Solution #1: add a @ sign before the call to mute any error message
@pg_query_params($db, $query, $params);
The drawback is that there'll be no log whatever the reason of the failure.
Solution #2: use pg_send_query_params(), process the error code, check that it is an expected error and ignore it only in this case, otherwise raise the error. Sample code:
if (pg_send_query_params($db, $query, $params)) {
$res=pg_get_result($db);
if ($res) {
$state = pg_result_error_field($res, PGSQL_DIAG_SQLSTATE);
if ($state==0) {
// success
}
else {
// an error happened
if ($state=="23505") { // unique_violation
// process or ignore expected error
}
else {
// process other errors
trigger_error (pg_last_error(), E_USER_ERROR);
}
}
}
}
else {
trigger_error ("pg_send_query_params failed:".pg_last_error(), E_USER_ERROR);
}
In both cases, there will be a trace of the error in the PostgreSQL error log unless you've muted it there too, but that's a separate problem that is generally solved by using a server-side INSERT with error trapping in procedural code rather than client-side.