PHP & MySQL: Truncate multiple tables

前端 未结 3 1492
醉梦人生
醉梦人生 2020-12-20 02:02

I tried to truncate a table but why is it not working? must something wrong in the database query?

$sql = \"TRUNCATE TABLE `table_name`\";

$result = $connec         


        
3条回答
  •  失恋的感觉
    2020-12-20 02:45

    thanks for the help guys! here is my answer,

    # 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'].'
    '; # 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); }

提交回复
热议问题