2010年12月29日星期三

Re: [fw-mvc] Zend_Db quote backslashes issue

On Thu, Dec 30, 2010 at 2:27 AM, Viktor Grandgeorg <info@intelligibel.de> wrote:
> Hello,
>
> it seems that Zend_Db does not escape backslashes right - or I'm doing something wrong:
>
> in my db table "dir" I have a column named "path" with the folowing entry:
>
> C:\some\path\with\backslahes
>
> In my DbTable class I'm doing something like:
>
> $path = "C:\some\path\with\backslahes"; // in reality the value comes from a config.ini
> $this->fetchAll(
>    $this->select()->where('path LIKE ?', $path));
>
> Now Zend_Db generates the following query:
>
> SELECT `dir`.* FROM `dir` WHERE (path LIKE 'C:\\some\\path\\with\\backslahes')
>
> This is wrong and the corresponding row never gets matched.
> It must be the following SQL query to match the right row(s):
>
> SELECT `dir`.* FROM `dir` WHERE (path LIKE 'C:\\\\some\\\\path\\\\with\\\\backslahes')
>
> Can somebody confirm this issue?

The query Zend generates looks right to me. What makes you think it
should be producing something with groups of four slashes?

What does the data actually look like when you select it out of the
DB? It should have only one slash (without you needing to do
stripslashes).
If it is coming out of the db like:
C:\\some\\path\\with\\backslahes
then it has been escaped too many times when you inserted it.


Paul

没有评论: