开发者

Do database row DeleteAll where 1 field is equal to something and other field is NOT equal to something

开发者 https://www.devze.com 2023-01-10 20:40 出处:网络
I\'m struggling with doing this, I want to basically do a database deleteAll where one field is equal to something and another field must NOT be equal to something.. its for deleting duplicate rows so

I'm struggling with doing this, I want to basically do a database deleteAll where one field is equal to something and another field must NOT be equal to something.. its for deleting duplicate rows so I want to delete all but one row.. the way I tried below isn't working, I Would appreciate any advice:

 $conditions = array (
  "Prox.proxy" => $currentproxytocheck,
  "AND" => array (
   "NOT" => array (
    "Prox.proxyid" => $currentproxyid
   )
  )
 );

$this->Prox->deleteAll(array( 'conditions' => $conditions)); 

EDIT:

The printout of my $conditions array is:

Array
(
    [Prox.proxy] => 62.58.179.2:80
    [AND] => Array
        (
            [NOT] => Array
                (
                    [Prox.pro开发者_如何学运维xyid] => 36829
                )

        )

)

Error from CAkephp:

Notice (8): Array to string conversion [CORE/cake/libs/model/datasources/dbo_source.php, line 2193]
Warning (512): SQL Error: 1054: Unknown column 'conditions' in 'where clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 673]   


The syntax for deleteAll is different from find

deleteAll(mixed $conditions, $cascade = true, $callbacks = false)

Use

$this->Prox->deleteAll($conditions); 

And your array could be built like so:

$conditions = array (
    "Prox.proxy" => $currentproxytocheck,
    "Prox.proxyid <>" => $currentproxyid
);

Which is the same thing, but more readable.

0

精彩评论

暂无评论...
验证码 换一张
取 消