Jump to content

Recommended Posts

I have a SQL statement which is difficult to use PDO on, it might not even be possible to do.

So I'm filtering it like this:

$search = $_GET['search'];
$search = preg_replace("/[^A-Za-z0-9]/", " ", $search);
$search = $mysqli->real_escape_string($search);

Will this result in an acceptable level of security?

Edited by anderson_catchme
Link to comment
https://forums.phpfreaks.com/topic/291107-how-good-or-bad-is-the-sql-filtering/
Share on other sites

How can a statement be 'difficult to use PDO on'?  Whatever do you mean?

 

It's a dynamic query for one, so id need to dynamically generate the question marks somehow. I just prefer strongly to filter this one, honestly. I also find PDO harder to debug.

Edited by anderson_catchme

None of this is a valid reason for giving up a robust solution in favor of some homegrown “filtering” stuff.

 

In fact, this makes absolutely no sense whatsoever. Where are the quotes? Why on earth would you replace non-alphanumerics with spaces? What is the mysqli_real_escape_string() supposed to do when you've already removed all of its target characters?

Prepared statements are indeed harder to debug, because there's no complete query at any point. The best you can get is a bunch of information about the parameters via PDOStatement::debugDumpParams(), but this doesn't even print the corresponding values.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.