Dranzaz has asked for the wisdom of the Perl Monks concerning the following question:
root@myserver scripts# perl migrate_data_short.pl########################################################### #!/usr/bin/perl -w use DBI; my ($st) = 0; if ( &db_connect() ) { exit (1); } print "Please insert some text: "; $sometext = <STDIN>; chomp ($sometext); $sql = qq { insert into my_table (update_1) values ('$sometext') }; $sth = $dbh->prepare($sql); $sth->execute(); if ( $DBI::err ) { if ( $DBI::err == 1062) { print "\nDatabase server error: $DBI::err \n"; print "Record already exists in database. \n"; $st++; } else { print "Database server error: $DBI::err \n"; $st++; } } $dbh->disconnect(); sub db_connect { my $user = "user"; my $pass = 'password'; my ($st) = 0; $dbh = DBI->connect("dbi:mysql:host=my.work.domain", $user, $pass) + or die "Database Connection not made: $DBI::errstr \n"; if ( ! $dbh ) { print "Error opening database: \n $DBI::err \n $DBI::errstr \n +"; $st++; } $dbh->do("use mydb"); return ($st); } ############################################################
If I omit the ' from "Coeur d'Alane" it posts just fine. How do I get chacters like this to be inserted to my db/table?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: MySQL question
by almut (Canon) on Nov 28, 2008 at 14:06 UTC | |
|
Re: MySQL question
by bradcathey (Prior) on Nov 28, 2008 at 14:15 UTC | |
by Dranzaz (Sexton) on Nov 28, 2008 at 14:34 UTC | |
by lostjimmy (Chaplain) on Nov 28, 2008 at 15:07 UTC | |
|
Re: MySQL question
by tirwhan (Abbot) on Nov 28, 2008 at 14:11 UTC | |
|
Re: MySQL question
by Dranzaz (Sexton) on Nov 28, 2008 at 14:04 UTC |