Last active
September 24, 2021 10:27
-
-
Save RuSPanzer/762f28125a49ce2c3e7d236e7fdaf441 to your computer and use it in GitHub Desktop.
truncate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Очищает таблицу с данными. Использовать только в служебных целях | |
* | |
* @param bool $are_you_sure передайте сюда true, если понимаете что хотите сделать | |
* @return bool | |
*/ | |
public function truncate($are_you_sure = false) | |
{ | |
if(!$are_you_sure) | |
{ | |
return true; | |
} | |
$connect = $this->getConnect(); | |
if($connect->begin_transaction()) | |
{ | |
$connect->query('SET FOREIGN_KEY_CHECKS=0;'); | |
$connect->query('TRUNCATE ' . static::$_tbl_name . ';'); | |
$connect->query('SET FOREIGN_KEY_CHECKS=1;'); | |
return $connect->commit(); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment