PHP и MySQL: усечение нескольких таблиц

Я попытался усечь стол, но почему он не работает? что-то не так в запросе базы данных?

$sql = "TRUNCATE TABLE `table_name`"; $result = $connection -> query($sql); 

В идеале, я хочу обрезать все таблицы за один раз – возможно ли это?

если вы задаетесь вопросом, что внутри класса, которое я использую для создания запросов к базе данных, вот оно,

 #connects the database and handling the result class __database { protected $connection = null; protected $error = null; #make a connection public function __construct($hostname,$username,$password,$database) { $this -> connection = new mysqli($hostname,$username,$password,$database); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } } ... #performs a query on the database public function query($query) { $result = $this -> connection -> query($query); if($result) { return $result; } else { $this -> error = $this -> connection -> error; return false; } } #display error public function get_error() { return $this -> error; } #closes the database connection when object is destroyed. public function __destruct() { $this -> connection -> close(); } } 

Благодарю.

редактировать:

    ниже, как я называю объект db,

     # the host used to access DB define('DB_HOST', 'localhost'); # the username used to access DB define('DB_USER', 'root'); # the password for the username define('DB_PASS', 'xxx'); # the name of your databse define('DB_NAME', 'xxx'); $connection = new __database(DB_HOST,DB_USER,DB_PASS,DB_NAME); 

    Related of "PHP и MySQL: усечение нескольких таблиц"

    Справочным руководством по MySQL

    http://dev.mysql.com/doc/refman/5.0/en/truncate-table.html

    Вы можете удалить только одну таблицу за раз, используя TRUNCATE.

    Вы можете попробовать выполнить несколько запросов в одном запросе PHP, используя «;» разделитель между ними.

    Спасибо за помощь, ребята! вот мой ответ,

     # truncate data from all table # $sql = "SHOW TABLES IN 1hundred_2011"; # or, $sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA LIKE '".DB_NAME."'"; # use the instantiated db connection object from the init.php, to process the query $tables = $connection -> fetch_all($sql); //print_r($tables); foreach($tables as $table) { //echo $table['TABLE_NAME'].'<br/>'; # truncate data from this table # $sql = "TRUNCATE TABLE `developer_configurations_cms`"; # use the instantiated db connection object from the init.php, to process the query # $result = $connection -> query($sql); # truncate data from this table $sql = "TRUNCATE TABLE `".$table['TABLE_NAME']."`"; # use the instantiated db connection object from the init.php, to process the query $result = $connection -> query($sql); } 

    У вас есть пара различных вариантов.

    • Запуск запроса для каждого усечения
    • Создайте хранимую процедуру, которая усечет все таблицы, которые вы хотите сделать.