PDO: Select field from DB which contains a backslash



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have table with this conent



ID|name
----------------
1 |My Shop No. 6


(Don't ask why the six is within the backslashes, I have no idea, I just have to work with it)



I try to select this specifc value from my table.
My query looks like this:



$sql = "SELECT `id` FROM shops WHERE `name` = :name";
$params = array(':name' => "My Shop No. 6");
$this->fetchOne($sql, $params); // the binding happens in my mysql class


This query does not return any data, it's stating that there is no entry.
When I monitor my SQL statements with the Neor Profiler SQL, I can see that the database is receiving this query:



SELECT `id` FROM shops WHERE `name` = 'My Shop No. \6\'


When I use this query directly in PHPMyAdmin, it also does not return any results.



How can I deal with this kind of case?



There is absolutly no option to change the data in the database.










share|improve this question






















  • Backslash has a meaning in PHP strings too. Try var_dump($params) to see what I mean. If fact you get it right in SQL and the syntax is the same.

    – Álvaro González
    Nov 15 '18 at 13:46












  • Okay, the problem is that I struggled to create an example case. The string value is actually coming from an URL parameter. Do you think that this is still a problem then? I also tried to replace the backslashes with double backslashes before passing them to the query. But that did not help at all.

    – Michael Walter
    Nov 15 '18 at 13:52











  • I made a var_dump. The output is the string as it was received via the url

    – Michael Walter
    Nov 15 '18 at 13:54











  • String literals are an entirely different thing. Trust var_dump(). If a single slash in the URL gets doubled at var_dump($_GET) you have a different problem.

    – Álvaro González
    Nov 15 '18 at 13:56











  • It does not get doubled in the var_dump. It's only doubled within the Neor Profiler / MySQL. Until then, the string has only one backslash

    – Michael Walter
    Nov 15 '18 at 13:59

















0















I have table with this conent



ID|name
----------------
1 |My Shop No. 6


(Don't ask why the six is within the backslashes, I have no idea, I just have to work with it)



I try to select this specifc value from my table.
My query looks like this:



$sql = "SELECT `id` FROM shops WHERE `name` = :name";
$params = array(':name' => "My Shop No. 6");
$this->fetchOne($sql, $params); // the binding happens in my mysql class


This query does not return any data, it's stating that there is no entry.
When I monitor my SQL statements with the Neor Profiler SQL, I can see that the database is receiving this query:



SELECT `id` FROM shops WHERE `name` = 'My Shop No. \6\'


When I use this query directly in PHPMyAdmin, it also does not return any results.



How can I deal with this kind of case?



There is absolutly no option to change the data in the database.










share|improve this question






















  • Backslash has a meaning in PHP strings too. Try var_dump($params) to see what I mean. If fact you get it right in SQL and the syntax is the same.

    – Álvaro González
    Nov 15 '18 at 13:46












  • Okay, the problem is that I struggled to create an example case. The string value is actually coming from an URL parameter. Do you think that this is still a problem then? I also tried to replace the backslashes with double backslashes before passing them to the query. But that did not help at all.

    – Michael Walter
    Nov 15 '18 at 13:52











  • I made a var_dump. The output is the string as it was received via the url

    – Michael Walter
    Nov 15 '18 at 13:54











  • String literals are an entirely different thing. Trust var_dump(). If a single slash in the URL gets doubled at var_dump($_GET) you have a different problem.

    – Álvaro González
    Nov 15 '18 at 13:56











  • It does not get doubled in the var_dump. It's only doubled within the Neor Profiler / MySQL. Until then, the string has only one backslash

    – Michael Walter
    Nov 15 '18 at 13:59













0












0








0








I have table with this conent



ID|name
----------------
1 |My Shop No. 6


(Don't ask why the six is within the backslashes, I have no idea, I just have to work with it)



I try to select this specifc value from my table.
My query looks like this:



$sql = "SELECT `id` FROM shops WHERE `name` = :name";
$params = array(':name' => "My Shop No. 6");
$this->fetchOne($sql, $params); // the binding happens in my mysql class


This query does not return any data, it's stating that there is no entry.
When I monitor my SQL statements with the Neor Profiler SQL, I can see that the database is receiving this query:



SELECT `id` FROM shops WHERE `name` = 'My Shop No. \6\'


When I use this query directly in PHPMyAdmin, it also does not return any results.



How can I deal with this kind of case?



There is absolutly no option to change the data in the database.










share|improve this question














I have table with this conent



ID|name
----------------
1 |My Shop No. 6


(Don't ask why the six is within the backslashes, I have no idea, I just have to work with it)



I try to select this specifc value from my table.
My query looks like this:



$sql = "SELECT `id` FROM shops WHERE `name` = :name";
$params = array(':name' => "My Shop No. 6");
$this->fetchOne($sql, $params); // the binding happens in my mysql class


This query does not return any data, it's stating that there is no entry.
When I monitor my SQL statements with the Neor Profiler SQL, I can see that the database is receiving this query:



SELECT `id` FROM shops WHERE `name` = 'My Shop No. \6\'


When I use this query directly in PHPMyAdmin, it also does not return any results.



How can I deal with this kind of case?



There is absolutly no option to change the data in the database.







mysql pdo mariadb






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 13:04









Michael WalterMichael Walter

914616




914616












  • Backslash has a meaning in PHP strings too. Try var_dump($params) to see what I mean. If fact you get it right in SQL and the syntax is the same.

    – Álvaro González
    Nov 15 '18 at 13:46












  • Okay, the problem is that I struggled to create an example case. The string value is actually coming from an URL parameter. Do you think that this is still a problem then? I also tried to replace the backslashes with double backslashes before passing them to the query. But that did not help at all.

    – Michael Walter
    Nov 15 '18 at 13:52











  • I made a var_dump. The output is the string as it was received via the url

    – Michael Walter
    Nov 15 '18 at 13:54











  • String literals are an entirely different thing. Trust var_dump(). If a single slash in the URL gets doubled at var_dump($_GET) you have a different problem.

    – Álvaro González
    Nov 15 '18 at 13:56











  • It does not get doubled in the var_dump. It's only doubled within the Neor Profiler / MySQL. Until then, the string has only one backslash

    – Michael Walter
    Nov 15 '18 at 13:59

















  • Backslash has a meaning in PHP strings too. Try var_dump($params) to see what I mean. If fact you get it right in SQL and the syntax is the same.

    – Álvaro González
    Nov 15 '18 at 13:46












  • Okay, the problem is that I struggled to create an example case. The string value is actually coming from an URL parameter. Do you think that this is still a problem then? I also tried to replace the backslashes with double backslashes before passing them to the query. But that did not help at all.

    – Michael Walter
    Nov 15 '18 at 13:52











  • I made a var_dump. The output is the string as it was received via the url

    – Michael Walter
    Nov 15 '18 at 13:54











  • String literals are an entirely different thing. Trust var_dump(). If a single slash in the URL gets doubled at var_dump($_GET) you have a different problem.

    – Álvaro González
    Nov 15 '18 at 13:56











  • It does not get doubled in the var_dump. It's only doubled within the Neor Profiler / MySQL. Until then, the string has only one backslash

    – Michael Walter
    Nov 15 '18 at 13:59
















Backslash has a meaning in PHP strings too. Try var_dump($params) to see what I mean. If fact you get it right in SQL and the syntax is the same.

– Álvaro González
Nov 15 '18 at 13:46






Backslash has a meaning in PHP strings too. Try var_dump($params) to see what I mean. If fact you get it right in SQL and the syntax is the same.

– Álvaro González
Nov 15 '18 at 13:46














Okay, the problem is that I struggled to create an example case. The string value is actually coming from an URL parameter. Do you think that this is still a problem then? I also tried to replace the backslashes with double backslashes before passing them to the query. But that did not help at all.

– Michael Walter
Nov 15 '18 at 13:52





Okay, the problem is that I struggled to create an example case. The string value is actually coming from an URL parameter. Do you think that this is still a problem then? I also tried to replace the backslashes with double backslashes before passing them to the query. But that did not help at all.

– Michael Walter
Nov 15 '18 at 13:52













I made a var_dump. The output is the string as it was received via the url

– Michael Walter
Nov 15 '18 at 13:54





I made a var_dump. The output is the string as it was received via the url

– Michael Walter
Nov 15 '18 at 13:54













String literals are an entirely different thing. Trust var_dump(). If a single slash in the URL gets doubled at var_dump($_GET) you have a different problem.

– Álvaro González
Nov 15 '18 at 13:56





String literals are an entirely different thing. Trust var_dump(). If a single slash in the URL gets doubled at var_dump($_GET) you have a different problem.

– Álvaro González
Nov 15 '18 at 13:56













It does not get doubled in the var_dump. It's only doubled within the Neor Profiler / MySQL. Until then, the string has only one backslash

– Michael Walter
Nov 15 '18 at 13:59





It does not get doubled in the var_dump. It's only doubled within the Neor Profiler / MySQL. Until then, the string has only one backslash

– Michael Walter
Nov 15 '18 at 13:59












1 Answer
1






active

oldest

votes


















0














Many products (PHP, MySQL, etc) use backslash as the escape character.



By itself, it is usually consumed by doing something to the character after it. For example, atb gives you the letters a and b separated by a tab (the usual interpretation of t).



Doubling up the backslash \xyz usually is intepreted thus: The first backslash escapes the second, so you get xyz.



If your string goes through multiple layers of code (eg, PDO plus MySQL), you might need twice as many backslashes, since each layer will turn \ into .



Another diagnostic tool is SELECT HEX(col) ... to see what was stored in the database. Examples:



610962 atb -- a=61, tab=09, b=62
615C7462 a\tb -- a=61, =5C, t=74, b=62


Back to your code:



$params = array(':name' => "My Shop No. 6");

6 is probably treated as just "6" (not everything has some escaped meaning)
" possibly caused a syntax error. Normally this is now to get a " inside a string

'My Shop No. \6\'


Now the pairs of backslashes are turned into single backslashes, then the string is handed to whoever is next.



(In these contexts, single- and double-quotes work the same.)






share|improve this answer























    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%2f53320127%2fpdo-select-field-from-db-which-contains-a-backslash%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Many products (PHP, MySQL, etc) use backslash as the escape character.



    By itself, it is usually consumed by doing something to the character after it. For example, atb gives you the letters a and b separated by a tab (the usual interpretation of t).



    Doubling up the backslash \xyz usually is intepreted thus: The first backslash escapes the second, so you get xyz.



    If your string goes through multiple layers of code (eg, PDO plus MySQL), you might need twice as many backslashes, since each layer will turn \ into .



    Another diagnostic tool is SELECT HEX(col) ... to see what was stored in the database. Examples:



    610962 atb -- a=61, tab=09, b=62
    615C7462 a\tb -- a=61, =5C, t=74, b=62


    Back to your code:



    $params = array(':name' => "My Shop No. 6");

    6 is probably treated as just "6" (not everything has some escaped meaning)
    " possibly caused a syntax error. Normally this is now to get a " inside a string

    'My Shop No. \6\'


    Now the pairs of backslashes are turned into single backslashes, then the string is handed to whoever is next.



    (In these contexts, single- and double-quotes work the same.)






    share|improve this answer



























      0














      Many products (PHP, MySQL, etc) use backslash as the escape character.



      By itself, it is usually consumed by doing something to the character after it. For example, atb gives you the letters a and b separated by a tab (the usual interpretation of t).



      Doubling up the backslash \xyz usually is intepreted thus: The first backslash escapes the second, so you get xyz.



      If your string goes through multiple layers of code (eg, PDO plus MySQL), you might need twice as many backslashes, since each layer will turn \ into .



      Another diagnostic tool is SELECT HEX(col) ... to see what was stored in the database. Examples:



      610962 atb -- a=61, tab=09, b=62
      615C7462 a\tb -- a=61, =5C, t=74, b=62


      Back to your code:



      $params = array(':name' => "My Shop No. 6");

      6 is probably treated as just "6" (not everything has some escaped meaning)
      " possibly caused a syntax error. Normally this is now to get a " inside a string

      'My Shop No. \6\'


      Now the pairs of backslashes are turned into single backslashes, then the string is handed to whoever is next.



      (In these contexts, single- and double-quotes work the same.)






      share|improve this answer

























        0












        0








        0







        Many products (PHP, MySQL, etc) use backslash as the escape character.



        By itself, it is usually consumed by doing something to the character after it. For example, atb gives you the letters a and b separated by a tab (the usual interpretation of t).



        Doubling up the backslash \xyz usually is intepreted thus: The first backslash escapes the second, so you get xyz.



        If your string goes through multiple layers of code (eg, PDO plus MySQL), you might need twice as many backslashes, since each layer will turn \ into .



        Another diagnostic tool is SELECT HEX(col) ... to see what was stored in the database. Examples:



        610962 atb -- a=61, tab=09, b=62
        615C7462 a\tb -- a=61, =5C, t=74, b=62


        Back to your code:



        $params = array(':name' => "My Shop No. 6");

        6 is probably treated as just "6" (not everything has some escaped meaning)
        " possibly caused a syntax error. Normally this is now to get a " inside a string

        'My Shop No. \6\'


        Now the pairs of backslashes are turned into single backslashes, then the string is handed to whoever is next.



        (In these contexts, single- and double-quotes work the same.)






        share|improve this answer













        Many products (PHP, MySQL, etc) use backslash as the escape character.



        By itself, it is usually consumed by doing something to the character after it. For example, atb gives you the letters a and b separated by a tab (the usual interpretation of t).



        Doubling up the backslash \xyz usually is intepreted thus: The first backslash escapes the second, so you get xyz.



        If your string goes through multiple layers of code (eg, PDO plus MySQL), you might need twice as many backslashes, since each layer will turn \ into .



        Another diagnostic tool is SELECT HEX(col) ... to see what was stored in the database. Examples:



        610962 atb -- a=61, tab=09, b=62
        615C7462 a\tb -- a=61, =5C, t=74, b=62


        Back to your code:



        $params = array(':name' => "My Shop No. 6");

        6 is probably treated as just "6" (not everything has some escaped meaning)
        " possibly caused a syntax error. Normally this is now to get a " inside a string

        'My Shop No. \6\'


        Now the pairs of backslashes are turned into single backslashes, then the string is handed to whoever is next.



        (In these contexts, single- and double-quotes work the same.)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 21:10









        Rick JamesRick James

        71k566106




        71k566106





























            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%2f53320127%2fpdo-select-field-from-db-which-contains-a-backslash%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







            Popular posts from this blog

            Kleinkühnau

            Makov (Slowakei)

            Deutsches Schauspielhaus