mysql_real_escape_string() advice please.

Hi there, I'm seeking best practice for an issue I've only just thought
about whilst learning the PHP basics, forgive me if the answer is very
obvious. :)

If I have a text field in a form that I want to apply a 512 max char count
on, what size text field should I actually create to store it in a mySQL
database?

I ask this because if I use mysql_real_escape_string($text) to safely
escape the submitted data, couldn't the char count increase well beyond the
512 max char count of the submitted data? If so how much extra room should I
allow to avoid truncating the string in the database? Do I just double the
max, for worst case scenario that every character in the string needs
escaping? Or does the function add potentially more than one extra character
like ' or \ per char that needs escaping?

my_field TEXT(1024) NOT NULL

Or am I being stupid and the escape characters are only to pass on the data
to mySQL safely, and are not actually stored in the database?

Thanks experts!

Richard
Richard [ Fr, 30 März 2007 18:42 ] [ ID #1674131 ]

Re: mysql_real_escape_string() advice please.

| Or am I being stupid and the escape characters are only to pass on the
data
| to mySQL safely, and are not actually stored in the database?

i don't know about 'stupid' but the rest answers your question.
Steve [ Fr, 30 März 2007 19:00 ] [ ID #1674133 ]

Re: mysql_real_escape_string() advice please.

Such a speedy service... thanks Steve!

Richard
Richard [ Fr, 30 März 2007 19:07 ] [ ID #1674134 ]

Re: mysql_real_escape_string() advice please.

"Richard" <donotuse [at] funpods.com> wrote in message
news:qs6dnbY9Bdwn3pDbnZ2dnUVZ8tijnZ2d [at] bt.com...
| Such a speedy service... thanks Steve!

actually, it was pretty slow...at least 15 minutes. ;^)

no problem...best of luck
Steve [ Fr, 30 März 2007 19:07 ] [ ID #1674136 ]
PHP » alt.php » mysql_real_escape_string() advice please.

Vorheriges Thema: Web Developer based in the Crawley/Gatwick area Required.
Nächstes Thema: beginner oop: class not alway working