How can I recognize these 4 characters between "[GS]" as SQL and not as PhP?

2

In the following php query but it does not allow me to remove this [GS] that is in brackets within the table as a record (NOTE: Below I leave a small Photo SQL Capture of my doubt I appreciate answers I think the picture explains better.)

$result3 = mssql_query(' UPDATE Ps_GameData.dbo.Chars 
SET CharName = replace (CharName,\'' **[GS]** '\' ,'' ) '); 

The error I get is the following:

Parse error: syntax error, unexpected [ in line 60

I want you to remove " [GS] " and leave the name empty.

Example:

The SQL query:

UPDATE PS_GameData.dbo.Chars SET CharName = replace (CharName, '**[GS]**' ,'')

Get this result:

[GS]Juan

In this case, I want to leave "Juan" simply without the content inside the bracket.

The SQL query works fine but I need to adapt this functionality using php.

Example:

$result3 = mssql_query(' UPDATE Ps_GameData.dbo.Chars 
SET CharName = \'**[**\'+\'**GS**\'+\'**]**\' + CharName ');

It works great, but I want to remove it now and I can not find the way it is used replace but I do not place the character settings so that the bracket is part of the SQL query php

I would like to delete the character [ before GS as would be the synthesis:

    $result3 = mssql_query("UPDATE Ps_GameData.dbo.Chars 
    SET  CharName = replace (CharName,'\'[ '\','') 

    
asked by Juan Carlos Villamizar Alvarez 16.07.2016 в 16:26
source

1 answer

0

You are putting the escape of the character in the wrong quote. Instead of this being%% co_:

$result3 = mssql_query(' UPDATE Ps_GameData.dbo.Chars SET CharName = replace (CharName,\'' [GS] '\' ,'' ) ');

should be in this other mode \'' :

$result3 = mssql_query(' UPDATE Ps_GameData.dbo.Chars SET CharName = replace (CharName,'\' [GS] '\' ,'' ) ');

You can see that the code editor colors the string correctly now.

Besides, as I put you in a comment, you could do everything easier if instead of encapsulating everything with single quotes, you would use a combination of single and double quotes, so you would not have to worry about escaping things within your chain:

$result3 = mssql_query(" UPDATE Ps_GameData.dbo.Chars SET CharName = replace (CharName, '[GS]' ,'' ) ");
    
answered by 16.07.2016 / 16:33
source