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

Friday, December 31, 2021

[FIXED] CakePHP 3: Truncate a table

 December 31, 2021     cakephp-3.0, orm     No comments   

Issue

How can I truncate a table with CakePHP 3.x

I get the truncate query by this:

$this->Coupons->schema()->truncateSql($this->Coupons->connection());

but what is the best practice to execute it


Solution

This code working well, thanks to @ndm for his comment that helped the answer to be better.

    //In Coupons Controller
    $this->Coupons->connection()->transactional(function ($conn) {
        $sqls = $this->Coupons->schema()->truncateSql($this->Coupons->connection());
        foreach ($sqls as $sql) {
            $this->Coupons->connection()->execute($sql)->execute();
        }
    });


Answered By - Eymen Elkum
  • 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