User Name
Password
AppleNova Forums » Programmer's Nook »

use addslashes for entries in mysql or just for query?


Register Members List Calendar Search FAQ Posting Guidelines
use addslashes for entries in mysql or just for query?
Thread Tools
nassau
Member
 
Join Date: Jul 2004
 
2006-01-14, 15:00

i don't know how to phrase my question really but here goes...

is it ok to have a value in mysql exactly like this
Code:
\bla'
or should it be
Code:
\\bla\'
what i wonder is if only the query needs to be addslashed or if the ectual entry also needs to be stored addslashed in the database.



thanks
  quote
pmazer
Member
 
Join Date: May 2005
Location: Atlanta, GA
Send a message via AIM to pmazer  
2006-01-15, 01:40

I don't really know what you mean. Do you mean that you want to do a MySQL query in PHP since that's what all your questions have been about? A query that looks like:

Code:
"SELECT * FROM table;"
should suffice. Getting more specific:

Code:
"SELECT * FROM table WHERE field = 'value';"
should also suffice.
  quote
nassau
Member
 
Join Date: Jul 2004
 
2006-01-15, 16:21

i know how to make queries thank you.

the question is; should i keep stored values addslashed in the database?
  quote
Gargoyle
http://ga.rgoyle.com
 
Join Date: May 2004
Location: In your dock hiding behind your finder icon!
 
2006-01-15, 17:34

I think your missing the point of addslashes! Addslashes is there to protect the database and/or the sql from getting messed up by having certian characters. The values in your database SHOULD NOT have slashes, 'cos then you are not storing the correct data!

Just to really throw a spanner in the works, you should be using mysql_real_escape_string!

OK, I have given up keeping this sig up to date. Lets just say I'm the guy that installs every latest version as soon as its available!
  quote
nassau
Member
 
Join Date: Jul 2004
 
2006-01-15, 18:27

so, let's assume someone wants to store the following in mysql
Code:
i'm the best
is it then good practice to store that in mysql as
Code:
i\'m the best



and btw, what is the real difference between mysql_real_escape_string and addslashes? they both appear to do the same thing.
  quote
spotcatbug
Veteran Member
 
Join Date: May 2004
Location: Clayton, NC
 
2006-01-15, 19:21

You store in your Db:
Code:
I'm the best
and you use in your queries:
Code:
I\'m the best
  quote
nassau
Member
 
Join Date: Jul 2004
 
2006-01-15, 20:00

ok, thanks
  quote
rollercoaster375
Senior Member
 
Join Date: Mar 2005
Location: UIllinois (Champaign, IL)
Send a message via AIM to rollercoaster375 Send a message via MSN to rollercoaster375 Send a message via Yahoo to rollercoaster375 Send a message via Skype™ to rollercoaster375 
2006-01-16, 11:09

mysql_real_escape_string() is prefered to addslashes(). If there's an issue with MySQL specifically, addslashes won't deal with it.

Same goes for other escaping functions - always use the closest provided one.
  quote
nassau
Member
 
Join Date: Jul 2004
 
2006-01-16, 15:14

makes sense, thanks
  quote
Posting Rules Navigation
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Post Reply

Forum Jump
Thread Tools

« Previous Thread | Next Thread »

All times are GMT -5. The time now is 05:34.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2024, AppleNova