Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 03-24-2010, 12:33 PM Insert string with '
Extreme Talker

Posts: 173
Trades: 0
I have a string that contains a single single quote (') as part of the string. How do I need to modify the string so that SQL will interpret the (') as part of the string and not the end of the string.

'PUMP-SUBMERS,401GPM@706'TDH,BMB,GRUNDFOS'
^ ^ ^
Beginning Feet End of string
dgkindy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-24-2010, 01:44 PM Re: Insert string with '
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Use TWO single quotes to escape the apostrophe.

401GPM@706''TDH
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-24-2010, 03:42 PM Re: Insert string with '
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Or, if you use mysql, use the escape character \:
Code:
mysql> create table tblX (description varchar(400));
Query OK, 0 rows affected (0.05 sec)

mysql> insert into tblX (description)
    -> values ('\'PUMP-SUBMERS,401GPM@706\'TDH,BMB,GRUNDFOS\'');
Query OK, 1 row affected (0.02 sec)

mysql> select * from tblX;
+--------------------------------------------+
| description                                |
+--------------------------------------------+
| 'PUMP-SUBMERS,401GPM@706'TDH,BMB,GRUNDFOS' |
+--------------------------------------------+
1 row in set (0.00 sec)
you have the addslashes() php function to make this automatically.
http://www.php.net/manual/en/function.addslashes.php
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-24-2010, 03:44 PM Re: Insert string with '
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Hmmm, nevermind me...
I just tested the "usual" way, as Chrishirst explained before, and had the pleasant surprise to see that mysql recognize it too.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-24-2010, 06:34 PM Re: Insert string with '
Extreme Talker

Posts: 173
Trades: 0
I did some rummaging around on the Internet after I posted the question. Found this as a solution.

mysql_real_escape_string($value->part_desc)
dgkindy is offline
Reply With Quote
View Public Profile
 
Old 03-24-2010, 06:54 PM Re: Insert string with '
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by dgkindy View Post
I did some rummaging around on the Internet after I posted the question. Found this as a solution.

mysql_real_escape_string($value->part_desc)
That would work of course, provided you were using PHP to create the query
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-25-2010, 03:39 AM Re: Insert string with '
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
Originally Posted by dgkindy View Post
I did some rummaging around on the Internet after I posted the question. Found this as a solution.

mysql_real_escape_string($value->part_desc)
The difference with addslahses() is that, as it's stated in the manual, you need to have a mysql installed on the same machine for this to work.
PHP will rely on a function present in the mysql server to do that.

Quote:
mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Insert string with '
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.04897 seconds with 12 queries