Hi,

Shouldn't you use the build in quotation functions in Zend_Db ($db->quote() | $db->quoteInto())?

Regards,

Pieter Kokx

岩崎輝之 schreef:
Hi, all.

I am using Zend_Db (1.0.3) and wondering how I should escape '%'
character in the LIKE query.

The right way I think for the legacy functions is something like the following.

$text = '100%ok';
$escaped_text = mysql_real_escape_string($text);
$wcard_escaped_text = mb_ereg_replace('([%_])', '\\\\1',
$escaped_text); // multibyte-safe
$sql .= " content LIKE '%" . $wcard_escaped_text . "%'";

The following works but only on MySQL, and it does not seem the Zend_Db way.

$text = '100%ok';
$escaped_text = mysqli_real_escape_string($db->getConnection(), $text);
$wcard_escaped_text = mb_ereg_replace('([%_])', '\\\\1', $escaped_text);
$sql .= " content LIKE '%" . $wcard_escaped_text . "%'";

Any better way?



Reply via email to