best practice addslashes? colum length

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
chidge
Forum Commoner
Posts: 29
Joined: Sat May 10, 2008 4:03 pm

best practice addslashes? colum length

Post by chidge »

so if I use addslashes do I need to double my colum sizes?

so for instance I have

Code: Select all

comments char(120),
and my php limits on 120 characters

so in my input I can only enter 60 quotes therefore (giving me 120 characters)

not that anyone is going to want to enter 60 quotes for the input but if they do..... it wont work. So should i double my table colum lengths?

is this worrying to much about it?
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: best practice addslashes? colum length

Post by Darhazer »

Do not use addslashes to escape the data you are inserting in the database. Use mysql_real_escape_query()
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: best practice addslashes? colum length

Post by Eric! »

Either one will expand your overall string length if there are characters to escape. Inserting strings longer than the table field can cause some old versions of MySQL to crash with certain table types. It's a good practice to make sure your strings don't exceed the max length by allowing for more room or truncating them.
Post Reply