Search code examples
phpmysqlsqlcreate-table

How to find the names of all tables created in the last SQL statement using PHP?


I have some code like the following:

$import = "CREATE TABLE foo..."; // an SQL import containing some CREATE TABLE, ALTER TABLE, etc.
$result = $mysqli->query($import) or die ($mysqli->error);

How do I find the names of all the tables that were created in the last SQL query (i.e. the $import statement)? I was wondering if there was a special way in MySQL to do this, rather than just searching the statement for CREATE TABLE, which is kind-of a dirty hack.


Solution

  • use the information_schema.TABLES

    $time = time();
    
    //create tables here  
    ...
    
    select table_name, create_time 
    from information_schema.TABLES
    where create_time > $time
    where table_schema = 'andomar'
    order by CREATE_TIME desc