Maintain forward slash from MySQL select in PHP
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
add a comment |
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
add a comment |
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
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
php mysql codeigniter
edited Nov 14 '18 at 7:32
ACD
asked Nov 14 '18 at 7:13
ACDACD
8941112
8941112
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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`
It's always the silly stuff that stumps us the longest :)
– Tordek
Nov 14 '18 at 7:46
add a comment |
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.
Hi, please read edit for the main goal. thanks for pointing out.
– ACD
Nov 14 '18 at 7:24
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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`
It's always the silly stuff that stumps us the longest :)
– Tordek
Nov 14 '18 at 7:46
add a comment |
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`
It's always the silly stuff that stumps us the longest :)
– Tordek
Nov 14 '18 at 7:46
add a comment |
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`
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`
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
add a comment |
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
add a comment |
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.
Hi, please read edit for the main goal. thanks for pointing out.
– ACD
Nov 14 '18 at 7:24
add a comment |
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.
Hi, please read edit for the main goal. thanks for pointing out.
– ACD
Nov 14 '18 at 7:24
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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