Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Real escape string and PDO [duplicate]

Tags:

php

mysql

pdo

I'm using PDO after migrating away from the mysql library. What do I use in place of the old real_escape_string function?

I need to escape single quotes so they will go into my database and I think there may be a better way to handle this without add(ing) slashes to all my strings. What should I be using?

like image 969
John Avatar asked Sep 15 '10 09:09

John


People also ask

Does PDO escape string?

Description ¶ PDO::quote() places quotes around the input string (if required) and escapes special characters within the input string, using a quoting style appropriate to the underlying driver.

Is mysqli_ real_ escape_ string deprecated?

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

What is real escape string?

The real_escape_string() / mysqli_real_escape_string() function escapes special characters in a string for use in an SQL query, taking into account the current character set of the connection. This function is used to create a legal SQL string that can be used in an SQL statement.

What is mysql_ escape_ string?

mysql_escape_string is one of PHP mysql extension functions. It escapes a string provided as parameter for the function. Escapes means prepends backslash ( \ ) to special characters. mysql_escape_string is designed to be used with mysql_query function, to safely pass MySQL query parameters to the query.


1 Answers

You should use PDO Prepare

From the link:

Calling PDO::prepare() and PDOStatement::execute() for statements that will be issued multiple times with different parameter values optimizes the performance of your application by allowing the driver to negotiate client and/or server side caching of the query plan and meta information, and helps to prevent SQL injection attacks by eliminating the need to manually quote the parameters.

like image 197
SteD Avatar answered Sep 21 '22 01:09

SteD