pg_query warning

0
Hello, I'm getting a duplicate key warning, with the code below, I tried to capture this message in some ways but I could not, I want to be able to parse this warning before it prints something on the screen. If it is duplicate key I will not print anything to the user, but if it is another error I want to print the error to the user.

    if ($consulta = pg_query($sql)){
        echo htmlspecialchars($sql) . " -- ".$arquivo." -  SQL OK<br>\n";
    }

I have tried the code below but in this case it prints me the error 2x.

    if ($consulta = pg_query($sql)){
        echo htmlspecialchars($sql) . " -- ".$arquivo." -  INSERIDO <br>\n";
    }else{
        echo htmlspecialchars($sql) . " -- ".$arquivo." -  FALHA NO SQL <br>\n";
            if (! (strrpos(pg_last_error(), "duplicate key") ) ) {
                echo "<b>ERRO --> ".pg_last_error()."</b><br />";
            } 
    }

If I leave only the first code it continues printing the warning.

    
asked by anonymous 27.09.2018 / 20:04

0 answers