Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there PHP mysql_real_escape_string for postgresql?

Tags:

php

postgresql

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

like image 492
Harsh Avatar asked May 17 '11 11:05

Harsh


People also ask

Can we use PHP with PostgreSQL?

PHP provides many functions for working directly with PostgreSQL databases. To connect to PostgreSQL using native functions, follow these steps: Use the following PHP code to connect to PostgreSQL and select a database.

Is mysql_real_escape_string deprecated?

This extension was deprecated in PHP 5.5. 0, and it was removed in PHP 7.0.

How do I escape a string in PostgreSQL?

PostgreSQL also accepts “escape” string constants, which are an extension to the SQL standard. An escape string constant is specified by writing the letter E (upper or lower case) just before the opening single quote, e.g., E'foo' .


2 Answers

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

like image 142
deceze Avatar answered Sep 20 '22 12:09

deceze


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.

like image 40
reko_t Avatar answered Sep 19 '22 12:09

reko_t