List:General Discussion« Previous MessageNext Message »
From:Sean McKenna Date:May 2 1999 12:16am
Subject:Re: processing apostrophes
View as plain text  
On Sat, 1 May 1999 22:12:50 +0000 (GMT), you wrote:

>I have just created a database which will hold around
>10 tables, with each table having a few thousand records.
>I made a perl script to allow me to populate the database
>easier. (There is no "old" database to move from, and the
>only mysql client I have is the line-based one ["INSERT
>INTO table VALUES..."]). The script uses the DBI::mysql
>interface.
>
>Here is the relevant portion of code...
>
>  $sth = $dbh->prepare(qq{
>    INSERT INTO $table VALUES ('$id', '$description', '$cost')
>  }) || die $dbh->errstr;
>
>The problem occurs when the value of $description contains an
>apostrophe (').  When I was entering the records manually
>("INSERT INTO table...") I knew I had to use two apostrophes
>for it to work (such as "INSERT INTO table VALUES ( 0,
>John''s Book", as an example).
>
>At the time this error occurred, these variables held values...
>
>  $id = 13022
>  $description = "Joshua's Promise Plaque--Each"
>  $cost = 10.20
>

not elegant but 

	$description  =~ s/'/''/g;

before the prepare will do the job.


Thread
processing apostrophesJeremy2 May
  • Re: processing apostrophesRenaud Bruyeron2 May
  • Re: processing apostrophes(Sean McKenna)2 May