Skip to content

Instantly share code, notes, and snippets.

@RuSPanzer
Last active September 24, 2021 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RuSPanzer/762f28125a49ce2c3e7d236e7fdaf441 to your computer and use it in GitHub Desktop.
Save RuSPanzer/762f28125a49ce2c3e7d236e7fdaf441 to your computer and use it in GitHub Desktop.
truncate
<?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