when i read this value it gives 'i haven\'t attended'

If that's the case, then at the time of writing you inserted \'i haven\\\'t attended.\' to the database;
meaning it was still quoted twice. I assume that you either have another $dbh->quote() on that value somewhere in your code - or you are looking at old data in the database, not at the freshly inserted data.
Did you check if the new insert succeeded or maybe failed for some reason?

The data retrieved from the database (and not quoted after retrieving) should give i haven't attended - no backslashes.

Update:

in the database the value is stored as: i haven\

That data is corrupted. It was inserted as "i haven\\'" - the "'" survived and was interpreted as string terminator because it was oddly quoted: the quoting did not affect it, it only quoted the other backslash. That's strange, it looks like manual tampering to me. If that's not the case, I am at a loss here =(

Cheers, Sören


In reply to Re^3: escaping special characters in mysql queries by Happy-the-monk
in thread escaping special characters in mysql queries by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.