note 43691 deleted from language.types.string by nlopess

From: Date: Wed, 30 Jun 2004 12:54:56 +0000
Subject: note 43691 deleted from language.types.string by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72173@lists.php.net to get a copy of this message
Note Submitter: tom(€)interfranz[dot]de ---- 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... :-(

« previous php.notes (#72173) next »