2

how to process php vars before trying to execute query? e.g. i am trying to insert text with ",' but it query couldn't execute? what is the best way to solve this with PDO class?

many thanks

2
  • You should refine your question more. What do you mean that you want to insert text with ",". Is it means that you want to insert all values to 1 coulmns seperated by , or any thing else Commented Apr 1, 2011 at 11:39
  • sorry for that. comma doesn't have any special meaning here. i want insert double and single quote characters. Commented Apr 1, 2011 at 12:15

4 Answers 4

5

Perhaps PDO::quote is what you are looking for: http://php.net/manual/en/pdo.quote.php

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

1 Comment

in my case this is a life savior
0

Take a look at both addslashes() and mysql_real_escape_string(). What's happening here is that a ' is a special character, meaning MySQL will treat it as part of it's syntax, instead of treating it as a string like you want. addslashes or mysql_real_escape_string will add a backslash \ before all single and double quotes (and others) to make them not part of the MySQL syntax.

Comments

0

You can use mysql_real_escape_string($string) to escape your incoming string so that ' and " will be escaped.

Comments

0

You should bind your PHP variables, not escape them.

$variable = "''''''''''''''''''";
$sth = $dbh->prepare('SELECT * FROM table WHERE column = ?');
$sth->execute(array($variable));

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.