samedi 25 avril 2015

How to add a single quote when I have single quote in PHP for SQL Management studio


I am having trouble with SQL Management studio and I do not want to connect to this SQL server I want to make the data ready for my lines to be inserted in this database I have a text file with the lines of strings that I want to insert in sql server the line is like this:

You're Doing It Wrong!!,Mike Walsh,Intermediate

So it should be like this to be ready for sql server.

You''re Doing It Wrong!!,Mike Walsh,Intermediate

I also have this in lines:

Never Have to Say "Mayday!!!" Again

Is this one going to become a problem? Should I have any plan for it also?

I tried to use addslash and then replace the slash with the a single quote by doing:

  $str=",('".addslashes ($array[0])."')";
     $str=str_replace("\\","\'",$str);
     echo $str;

I did the comma and parenthesis for when I have insert to query in sql server the result of this one will be:

    ,('You\''re Doing It Wrong!!'),
,('Never Have to Say \'"Mayday!!!\'" Again'),

What did I do wrong here?


Aucun commentaire:

Enregistrer un commentaire