ewhitt has asked for the wisdom of the Perl Monks concerning the following question:
When I try to add strings with quotes, I receive SQL syntax errors (i.e. the "Publisher" key and keys with "O'Reilly"). What is the best way to handle quotes in this scenario? This is how I am doing the insert$VAR14 = { 'image_medium' => 'http://ecx.images-amazon.com/images/I/51 +p2cN2yIML._SL160_.jpg', 'authors' => 'Tony Stubblebine', 'publication_date' => '2007-07-18', 'title' => 'Regular Expression Pocket Reference: Regular Ex +pressions for Perl, Ruby, PHP, Python, C, Java and .NET (Pocket Refer +ence (O\'Reilly))', 'isbn' => '0596514271', 'publisher' => 'O\'Reilly Media, Inc.', 'image_small' => 'http://ecx.images-amazon.com/images/I/51p +2cN2yIML._SL75_.jpg', 'url_amazon' => 'http://www.amazon.com/Regular-Expression-P +ocket-Reference-Expressions/dp/0596514271%3FSubscriptionId%3D1VD4TGW1 +VSXT1RE5Y2G2%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D1 +65953%26creativeASIN%3D0596514271', 'pages' => '126' };
Thanks!$insert = "INSERT into books ( id, title, authors, isbn, pages, publisher, publication_date, image_small, image_medium, url_amazon, createdAt) VALUES ( NULL, '" . $hash{$key}{'title'} . "', '" . $hash{$key}{'authors'} . "', '" . $hash{$key}{'isbn'} . "', '" . $hash{$key}{'pages'} . "', '" . $hash{$key}{'publisher'} . "', '" . $hash{$key}{'publication_date'} . "', + '" . $hash{$key}{'image_small'} . "', '" . $hash{$key}{'image_medium'} . "', '" . $hash{$key}{'url_amazon'} . "', NULL)"; $sth = $dbh->prepare($insert);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Best way to deal with quotes in string with DBI
by psini (Deacon) on Jul 27, 2008 at 13:28 UTC | |
|
Re: Best way to deal with quotes in string with DBI
by bradcathey (Prior) on Jul 27, 2008 at 15:02 UTC | |
by Jenda (Abbot) on Jul 27, 2008 at 22:48 UTC | |
|
Re: Best way to deal with quotes in string with DBI
by Your Mother (Archbishop) on Jul 27, 2008 at 18:26 UTC | |
|
Re: Best way to deal with quotes in string with DBI
by ruzam (Curate) on Jul 28, 2008 at 00:30 UTC | |
by Burak (Chaplain) on Jul 28, 2008 at 10:57 UTC | |
by ruzam (Curate) on Jul 28, 2008 at 14:14 UTC |