13

Is there PHP mysql_real_escape_string for postgresql? if yes then how ? please Give the Examples? & also the work of this string

4 Answers 4

11

See pg_escape_string at http://www.php.net/manual/en/function.pg-escape-string.php.

Sign up to request clarification or add additional context in comments.

2 Comments

stackoverflow.com/questions/6029240/… not working ...plz help me
It wil takes '~!@#$%^*()_=-{}|][:"';<>?/.,'except& and +` string.
8

Alternatively you could use prepared statements (pg_prepare) and placeholders ($1, $2, etc), and then give the arguments for the query in pg_execute. This would be my preferred way as it's not only cleaner, but also safer in the long run since there's no chance for SQL injections if you always use placeholders in prepared statements.

1 Comment

There's an example in the pg_prepare documentation page.
3

Use pg_query_params():

<?php    
$result = pg_query_params(
      $dbconn, // database connection
      'SELECT * FROM foo WHERE bar = $1 AND baz = $2', // query using placeholders
      array('value 1','value 2') // all values for the placeholders in a single array
    );
?>

Save and very eary to use.

Comments

2

You have both pg_escape_string and pg_escape_bytea available.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.