0

I try to test a query from a PHP file without answer if there is an error.

For example, if I do that :

<?php

$dbconnect = pg_connect("host=localhost port=5432 dbname=" . $_POST['data1'] . " user=postgres password=jtgacdt");

$param = array ();
$result = pg_query($dbconnect,$_POST['data3']));
// $result = pg_query($dbconnect,'pg_query($dbconnect,' . $_POST['data3'] . ')';

if (!$result) {
    $param ['titre'] = 'Oh no !';
    $param ['message'] = 'Id doesn\'t work';
    $param ['type'] = 'error';
    echo json_encode ($param);
} else {
    $param ['titre'] = 'Yes';
    $param ['message'] = 'Cool';
    $param ['type'] = 'Success';
};

pg_close($dbconnect);

?>

I don't have echo out of my condition code because I want to only return my parameters 'titre', 'message' and 'type', not that :


Warning: pg_query() [function.pg-query]: Query failed: ERROR (...)

But I've this error message AND my parameters...

I've a precision, I call this code with Ajax :

$.ajax({type: "POST", url: "script\\php\\postgres_php.php",data: {data1:db,data3:request}, async: false});

I tried function pg_query_params but it the same thing... It is possible to test the errors and control the echo of my PHP ?

3
  • 3
    Please do not do this. SQL injection is one thing, but accepting an entire SQL query from user input is just crazy and dangerous. As for the actual issue, have a look at the docs for ini settings. specifically display_errors, and error_reporting. Commented Sep 6, 2016 at 13:06
  • pg_last_error doesn't work for me, pg_last_error return '' and Okay Jon, Thank you for your answer Commented Sep 6, 2016 at 13:19
  • If I use pg_query_params(...) I've the same probem, in the answer of my PHP I've "<b>Warning</b>: pg_query_params() [<a href= (...)" Commented Sep 6, 2016 at 13:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.