Disinfect all user input in PostgreSQL using PHP

This question is based on this topic .

Do you need explicit disinfection when using pg_prepare?

I feel that pg_prepare automatically sanitizes the user login, so we don’t need it

 $question_id = filter_input(INPUT_GET, 'questions', FILTER_SANITIZE_NUMBER_INT);

The context in which I use Postgres

 $result = pg_prepare($dbconn, "query9", "SELECT title, answer
     FROM answers 
     WHERE questions_question_id = $1;");                                  
 $result = pg_execute($dbconn, "query9", array($_GET['question_id']));
+3
source share
1 answer

According to the Postgres documentation in pg_prepare, all escaping is done for you. See the Examples section for the following code (including comments):

<?php
// Connect to a database named "mary"
$dbconn = pg_connect("dbname=mary");

// Prepare a query for execution
$result = pg_prepare($dbconn, "my_query", 'SELECT * FROM shops WHERE name = $1');

// Execute the prepared query.  Note that it is not necessary to escape
// the string "Joe Widgets" in any way
$result = pg_execute($dbconn, "my_query", array("Joe Widgets"));

// Execute the same prepared query, this time with a different parameter
$result = pg_execute($dbconn, "my_query", array("Clothes Clothes Clothes"));
?>

, (') (") , $1 .

+4

Source: https://habr.com/ru/post/1714687/


All Articles