note 43691 added to language.types.string

From: Date: Wed, 30 Jun 2004 12:48:05 +0000
Subject: note 43691 added to language.types.string
Groups: php.notes 
Request: Send a blank email to php-notes+get-72172@lists.php.net to get a copy of this message
i found out, that not only the php-parser uses c-syntax for escaping special characters but also does mysql. the mysql parser also cuts the escape characters which in the end doubles the number of backslashes to use. this makes it 16! backslashes for the LIKE comparison to work. so mysql regards \\\\ as a single \ and php also demands \\ for \ to print. first of all php cuts \\\\\\\\\\\\\\\\ in half => \\\\\\\\ and mysql (which uses \\\\ for \) makes it \\ in the end... [so the hierarchy of commands executed is important to know for this point determines the number of slashes to use...] example: imagine you had a database with a column with stored UNC pathes. they look like: \\servername\share\path\... now if you want to filter for a specific server and you utilize the LIKE comparison offered by mySQL your syntax looks like this: $query = "SELECT * FROM [db] WHERE [column] LIKE '\\\\\\\\\\\\\\\\UNCpath\\\\\\\\'"; simple math, huh!? though it cost me almost a day to find out... :-( ---- Manual Page -- http://www.php.net/manual/en/language.types.string.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43691 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43691&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43691&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#72172) next »