PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 21, 2022

[FIXED] How to write update query in cakephp

 April 21, 2022     cakephp, cakephp-2.0, cakephp-2.1, cakephp-2.3     No comments   

Issue

$test="test's";   
$contact='1234567890';
 $this->Page->updateAll(
        array('Page.order' => 0,"Page.name" => "'$test'","Page.contact" => "'$contact'"),
        array('Page.type' => 'PROMOTED')
    );

Above query having single quote conflict. Is there any other way to write update query . I am using cakephp 2x


Solution

NOTE: Must backslash characters that have another meaning in php if you want them to be recognized as string caharacters. e.g(test's needs be test\'s)

http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-updateall-array-fields-mixed-conditions

try:

$db = $this->getDataSource();
$test = $db->value('test\'s');
$contact = $db->value('1234567890');
$this->Page->updateAll(
        array('Page.order' => 0,"Page.name" => $test,"Page.contact" =>     $contact),
    array('Page.type' => 'PROMOTED')
);


Answered By - Jason Joslin
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing