Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2007
    Posts
    19

    Unanswered: Escape ' (single quote) in PHP

    Hi,

    I import the content of a csv file into a db2 database.

    In the file are some cells that contain a ' (single quote). This causes problems and the respective cell won't be importet.

    Now I replace all single quotes with two single quotes in succession. Then it works. But now I have instead of the orginal value O'Reilly --> the value O''Reilly in the database.

    E.g., for the mysql datapase PHP provides a function to escape such characters. Is there anything like this for DB2?

    I already opened a thread in the DB2 Forum, but they forwarded me to this fourm!
    http://www.dbforums.com/showthread.php?t=1619002

    Chris

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    in the other thread, you said you are doing this --

    insert into User.Ausschnitt values ('O'reilly','2','3','4','5','6');

    now in this thread, suddenly you're importing a CSV

    which is it?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    See the PHP db2_escape_string(...) function.

  4. #4
    Join Date
    Jun 2007
    Posts
    19
    @r937: I want to import a csv file, but to simplify the issue I just said how to import a value with single quotes in general because there is the same problem.

    @dbmab: I found this function one time and I tried it at once but I only got the message "Call to undefined function ... ". Is it possible that my PHP is not up to date?

    I have installed XAMPP on my machine (with PHP 5.2.2). It doesn't know this function.

  5. #5
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    If you are able to use other PHP db2 functions, it is possible that that one does not exist yet in the version you are using (or at all.) PHP 5.2.3 is out, but I doubt one of the things changed was to add that function.

    If using a \ meets the db2 escape character requirements, you can use the PHP addcslashes() function. If two single quotes are needed, you would need to use something like the str_replace() function.

  6. #6
    Join Date
    Jun 2007
    Posts
    19
    I used both addslashes() and str_replace! str_replace has the effect that single quotes become double quotes or two single quotes in succession. addslashes() has no effect. But thanks for your help! I will keep on searching and trying! If you have other ideas please feel free.

  7. #7
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Quote from : http://www.ispirer.com/doc/sqlways38...ays-1-034.html

    The escape character is a double quotation mark ("), except for those cases when the string delimiter is set to double quotation mark. In this case the escape character is apostrophe (')

  8. #8
    Join Date
    Jun 2007
    Posts
    19
    Thx! It works!

    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •