Current location: Hot Scripts Forums » Programming Languages » Perl » Unable to write a single quote (') to a MySQL database


Unable to write a single quote (') to a MySQL database

Reply
  #1 (permalink)  
Old 10-08-05, 08:06 AM
abtimoteo abtimoteo is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Question Unable to write a single quote (') to a MySQL database

1. Is there a special way to parse form input containing single quotes for MySQL?

2. My scripts have been able to parse input with single quotes for STDOUT and the mail. But strings with single quotes can not be written to a MySQL database.

3. Thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 10-10-05, 07:51 AM
ser ser is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Try to use $dbh->quote() as shown in example
Code:
#!/usr/bin/perl

  use strict;
  use DBI();

  my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost",
                         "user", "password",
                         {'RaiseError' => 1});
[skipped]

  $dbh->do("INSERT INTO foo VALUES (1, " . $dbh->quote($string_with_quotes) . ")");

  $dbh->disconnect();
You also can replace '(single quote) with '' (two single quotes), or \' if your mysql support it.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
Flat file vs mysql database Imusion PHP 5 06-13-06 12:10 PM
MicroOLAP Database Designer for MySQL 1.8 Released microolap General Advertisements 1 09-20-05 10:00 AM
Clear my misunderstanding: 1 MySQL database for many programs? iKwak PHP 3 08-21-05 12:50 PM
Need help to store images in mysql database sjems PHP 2 04-12-05 05:36 AM


All times are GMT -5. The time now is 04:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.