How can I check if a MySQL table exists with PHP?

前端 未结 12 1647
小鲜肉
小鲜肉 2020-12-02 13:08

As simple in theory as it sounds I\'ve done a fair amount of research and am having trouble figuring this out.

How can I check if a MySQL table exists and if it does

12条回答
  •  北海茫月
    2020-12-02 14:02

    $res = mysql_query("SELECT table_name FROM information_schema.tables WHERE table_schema = '$databasename' AND table_name = '$tablename';");
    

    If no records are returned then it doesn't exist.

提交回复
热议问题