Hi all

How do I check if a table exists in a MySQL database?

Thanks

    for what purpose do you want to to that?

    you might want to use

    $existent = mysql_num_rows(mysql_query("SHOW TABLES LIKE 'name of table'")) == 1;

    if you want to create it if it does not exist

    CREATE TABLE IF NOT EXISTS tablename( ... )

    will help

      Hi and thanks

      That code looks like it should do the job - I just want it to check if a table exists to check if a script is installed.

      Thanks

        another method i just found is this

        function mysql_table_exists($table, $link)
        {
        $exists = mysql_query("SELECT 1 FROM $table LIMIT 0", $link);
        if ($exists) return true;
        return false;
        }

          Write a Reply...