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


i having trouble sql management studio , not want connect sql server want make data ready lines inserted in database have text file lines of strings want insert in sql server line this:

you're doing wrong!!,mike walsh,intermediate

so should ready sql server.

you''re doing wrong!!,mike walsh,intermediate

i have in lines:

never have "mayday!!!" again

is 1 going become problem? should have plan also?

i tried use addslash , replace slash single quote doing:

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

i did comma , parenthesis when have insert query in sql server result of 1 be:

    ,('you\''re doing wrong!!'), ,('never have \'"mayday!!!\'" again'), 

what did wrong here?

using prepared statements best way. if insist on regex way, can double single quotes preg_replace there number of consequent single quotes:

''|(') 

and replace ''. see demo

sample php code:

$re = "/''|(')/";  $str = "you're doing wrong!!,'''mike walsh'',intermediate";  $subst = "''";  $result = preg_replace($re, $subst, $str); 

output:

you''re doing wrong!!,''''mike walsh'',intermediate 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -