Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2531075
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: Mysql/postgreSQL

2012-08-21 09:07:05

MySQL清空某个数据库中的表使用 truncate,如果你想知道怎样删除某个数据库中的表请访问:这里。 MySQL清空某个数据库中的表SQL语句: 
truncate table_name 
PHP代码: mysql_query("truncate table_name"); 
PHP脚本清空数据库中的表:

点击(此处)折叠或打开

  1. /*
  2. * Connect to Mysql Database
  3. */
  4. $con=mysql_connect('localhost','username','password');
  5. mysql_select_db('database_name');
  6. /*
  7. * Get all the tables in the database
  8. */
  9. $database_tables = mysql_query('show tables');
  10. /*
  11. * Define the tables to preserve data
  12. */
  13. $preserve_tables = array('test1');//不清空数据的表
  14. /*
  15. * Check the tables to clean up and clear all the data
  16. */
  17. while($row=mysql_fetch_array($database_tables)){
  18.     $table = trim($row[0]);
  19.     if(!(in_array($table,$preserve_tables))){
  20.         mysql_query("truncate ".$table);
  21.     }
  22. }

阅读(3588) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~