Maintain forward slash from MySQL select in PHP










0















DIRECT FROM DB



When I select directly from db I get the forward slash without problem.



Query:



SELECT REPLACE(`row`, '"', '\"') as data FROM `table`


Direct query result:



a:1:i:0;s:0:"";


FROM PHP



But when done in PHP (specifically CI), forward slash are gone.
Query string:



"SELECT REPLACE(`row`, '"', '\"') as data FROM `table`"


Query from PHP result:



a:1:i:0;s:0:"";


Question:
How do I maintain the forward slash in PHP?




Note: Im trying to have a group_concat with other values as json format string so I need the slashes so it doesn't break the format, sample complete output:



"field_1":"Some Value","field_2":"a:1:i:0;s:0:"";"









share|improve this question




























    0















    DIRECT FROM DB



    When I select directly from db I get the forward slash without problem.



    Query:



    SELECT REPLACE(`row`, '"', '\"') as data FROM `table`


    Direct query result:



    a:1:i:0;s:0:"";


    FROM PHP



    But when done in PHP (specifically CI), forward slash are gone.
    Query string:



    "SELECT REPLACE(`row`, '"', '\"') as data FROM `table`"


    Query from PHP result:



    a:1:i:0;s:0:"";


    Question:
    How do I maintain the forward slash in PHP?




    Note: Im trying to have a group_concat with other values as json format string so I need the slashes so it doesn't break the format, sample complete output:



    "field_1":"Some Value","field_2":"a:1:i:0;s:0:"";"









    share|improve this question


























      0












      0








      0








      DIRECT FROM DB



      When I select directly from db I get the forward slash without problem.



      Query:



      SELECT REPLACE(`row`, '"', '\"') as data FROM `table`


      Direct query result:



      a:1:i:0;s:0:"";


      FROM PHP



      But when done in PHP (specifically CI), forward slash are gone.
      Query string:



      "SELECT REPLACE(`row`, '"', '\"') as data FROM `table`"


      Query from PHP result:



      a:1:i:0;s:0:"";


      Question:
      How do I maintain the forward slash in PHP?




      Note: Im trying to have a group_concat with other values as json format string so I need the slashes so it doesn't break the format, sample complete output:



      "field_1":"Some Value","field_2":"a:1:i:0;s:0:"";"









      share|improve this question
















      DIRECT FROM DB



      When I select directly from db I get the forward slash without problem.



      Query:



      SELECT REPLACE(`row`, '"', '\"') as data FROM `table`


      Direct query result:



      a:1:i:0;s:0:"";


      FROM PHP



      But when done in PHP (specifically CI), forward slash are gone.
      Query string:



      "SELECT REPLACE(`row`, '"', '\"') as data FROM `table`"


      Query from PHP result:



      a:1:i:0;s:0:"";


      Question:
      How do I maintain the forward slash in PHP?




      Note: Im trying to have a group_concat with other values as json format string so I need the slashes so it doesn't break the format, sample complete output:



      "field_1":"Some Value","field_2":"a:1:i:0;s:0:"";"






      php mysql codeigniter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 7:32







      ACD

















      asked Nov 14 '18 at 7:13









      ACDACD

      8941112




      8941112






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Your two queries are not equivalent: your PHP code evaluates to



          php > echo "SELECT REPLACE(`row`, '"', '\"') as data FROM `table`";
          SELECT REPLACE(`row`, '"', '"') as data FROM `table`


          You're only escaping a single slash; you need an extra pair:



          "SELECT REPLACE(`row`, '"', '\\"') as data FROM `table`"


          which results in your original query:



          php > echo "SELECT REPLACE(`row`, '"', '\\"') as data FROM `table`";
          SELECT REPLACE(`row`, '"', '\"') as data FROM `table`





          share|improve this answer























          • It's always the silly stuff that stumps us the longest :)

            – Tordek
            Nov 14 '18 at 7:46


















          0














          I dont get what goal is this, but maybe you can use this bro. the same result as forwards slashes.



          json_encode(); 


          When select, just return json_encode($value) so that it will maintain the forward slashes.






          share|improve this answer























          • Hi, please read edit for the main goal. thanks for pointing out.

            – ACD
            Nov 14 '18 at 7:24










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294862%2fmaintain-forward-slash-from-mysql-select-in-php%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Your two queries are not equivalent: your PHP code evaluates to



          php > echo "SELECT REPLACE(`row`, '"', '\"') as data FROM `table`";
          SELECT REPLACE(`row`, '"', '"') as data FROM `table`


          You're only escaping a single slash; you need an extra pair:



          "SELECT REPLACE(`row`, '"', '\\"') as data FROM `table`"


          which results in your original query:



          php > echo "SELECT REPLACE(`row`, '"', '\\"') as data FROM `table`";
          SELECT REPLACE(`row`, '"', '\"') as data FROM `table`





          share|improve this answer























          • It's always the silly stuff that stumps us the longest :)

            – Tordek
            Nov 14 '18 at 7:46















          1














          Your two queries are not equivalent: your PHP code evaluates to



          php > echo "SELECT REPLACE(`row`, '"', '\"') as data FROM `table`";
          SELECT REPLACE(`row`, '"', '"') as data FROM `table`


          You're only escaping a single slash; you need an extra pair:



          "SELECT REPLACE(`row`, '"', '\\"') as data FROM `table`"


          which results in your original query:



          php > echo "SELECT REPLACE(`row`, '"', '\\"') as data FROM `table`";
          SELECT REPLACE(`row`, '"', '\"') as data FROM `table`





          share|improve this answer























          • It's always the silly stuff that stumps us the longest :)

            – Tordek
            Nov 14 '18 at 7:46













          1












          1








          1







          Your two queries are not equivalent: your PHP code evaluates to



          php > echo "SELECT REPLACE(`row`, '"', '\"') as data FROM `table`";
          SELECT REPLACE(`row`, '"', '"') as data FROM `table`


          You're only escaping a single slash; you need an extra pair:



          "SELECT REPLACE(`row`, '"', '\\"') as data FROM `table`"


          which results in your original query:



          php > echo "SELECT REPLACE(`row`, '"', '\\"') as data FROM `table`";
          SELECT REPLACE(`row`, '"', '\"') as data FROM `table`





          share|improve this answer













          Your two queries are not equivalent: your PHP code evaluates to



          php > echo "SELECT REPLACE(`row`, '"', '\"') as data FROM `table`";
          SELECT REPLACE(`row`, '"', '"') as data FROM `table`


          You're only escaping a single slash; you need an extra pair:



          "SELECT REPLACE(`row`, '"', '\\"') as data FROM `table`"


          which results in your original query:



          php > echo "SELECT REPLACE(`row`, '"', '\\"') as data FROM `table`";
          SELECT REPLACE(`row`, '"', '\"') as data FROM `table`






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 7:41









          TordekTordek

          7,09122861




          7,09122861












          • It's always the silly stuff that stumps us the longest :)

            – Tordek
            Nov 14 '18 at 7:46

















          • It's always the silly stuff that stumps us the longest :)

            – Tordek
            Nov 14 '18 at 7:46
















          It's always the silly stuff that stumps us the longest :)

          – Tordek
          Nov 14 '18 at 7:46





          It's always the silly stuff that stumps us the longest :)

          – Tordek
          Nov 14 '18 at 7:46













          0














          I dont get what goal is this, but maybe you can use this bro. the same result as forwards slashes.



          json_encode(); 


          When select, just return json_encode($value) so that it will maintain the forward slashes.






          share|improve this answer























          • Hi, please read edit for the main goal. thanks for pointing out.

            – ACD
            Nov 14 '18 at 7:24















          0














          I dont get what goal is this, but maybe you can use this bro. the same result as forwards slashes.



          json_encode(); 


          When select, just return json_encode($value) so that it will maintain the forward slashes.






          share|improve this answer























          • Hi, please read edit for the main goal. thanks for pointing out.

            – ACD
            Nov 14 '18 at 7:24













          0












          0








          0







          I dont get what goal is this, but maybe you can use this bro. the same result as forwards slashes.



          json_encode(); 


          When select, just return json_encode($value) so that it will maintain the forward slashes.






          share|improve this answer













          I dont get what goal is this, but maybe you can use this bro. the same result as forwards slashes.



          json_encode(); 


          When select, just return json_encode($value) so that it will maintain the forward slashes.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 7:17









          j3thamzj3thamz

          764




          764












          • Hi, please read edit for the main goal. thanks for pointing out.

            – ACD
            Nov 14 '18 at 7:24

















          • Hi, please read edit for the main goal. thanks for pointing out.

            – ACD
            Nov 14 '18 at 7:24
















          Hi, please read edit for the main goal. thanks for pointing out.

          – ACD
          Nov 14 '18 at 7:24





          Hi, please read edit for the main goal. thanks for pointing out.

          – ACD
          Nov 14 '18 at 7:24

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294862%2fmaintain-forward-slash-from-mysql-select-in-php%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3