I've got some simple updates inside my migration with strings that may contain special characters. For example:
$this->execute("UPDATE `setting` SET `classname` = 'org\foo\Bar' WHERE `id` = 1 ");
The problem with this for example, org\foo\Bar
when inserted into MySQL treats \
as escape characters. For each DB phinx
supports, I'm sure there are special characters that need to be handled in strings that when using PDO
directly you'd get around by using prepared statements and binding parameters.
Is there any native way in phinx
to escape strings or do I need to fall back on something like PDO::quote()
?
As alluded to in Charlotte's OP comments, it doesn't look like this feature exists. The work around is the following:
quote()
or manually construct a query using the connection directlyHere's my code example using quote()
public function change()
{
$conn = $this->getAdapter()->getConnection();
$quotedString = $conn->quote('org\foo\Bar');
$this->execute("UPDATE `setting` SET `classname` = $quotedString WHERE `id` = 1 ");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With