删除表中的SQL语法错误

时间:2015-04-09 10:06:27

标签: php mysql syntax

我使用phpMyadmin作为数据库,我不能删除表格...如何发现语法错误?

<?php       
include 'dbconnect.php';  //connect to DB  
//Droping The tables  
$dropping = @mysql_query('DROP TABLE IF EXISTS rents, criticise, writesIn, writenIn, translated, reads, worksIn, inStock, playsIN, store, genre, employee, newspaper, customer, critic, language, actor, film, city ;'); 
if (!$dropping) {   
  exit('<p>Error dropping the tables<br />'.   
      'Error: ' . mysql_error() . '</p>');   
}       
if ($dropping) {   
  echo 'everything went just fine dropping the tables<br>';   
}

2 个答案:

答案 0 :(得分:1)

readsreserved MySQL keyword。你需要将它包含在反引号中:

DROP TABLE IF EXISTS rents, criticise, writesIn, writenIn, translated, `reads`, worksIn, inStock, playsIN, store, genre, employee, newspaper, customer, critic, language, actor, film, city

答案 1 :(得分:0)

$dropping = @mysql_query('DROP TABLE IF EXISTS rents, criticise, writesIn, writenIn, translated, `reads`, worksIn, inStock, playsIN, store, genre, employee, newspaper, customer, critic, language, actor, film, city  '); 

删除分号;并使用reads的反引号作为关键字