I have following query:
CREATE TABLE `test` ( `col1` INT( 10 ) NOT NULL , `col2` VARCHAR( 50 ) NOT NULL , `col3` DATE NOT NULL ) ENGINE = MYISAM ; I want to write a general php script that get table name(test) from above query.
I have following query:
CREATE TABLE `test` ( `col1` INT( 10 ) NOT NULL , `col2` VARCHAR( 50 ) NOT NULL , `col3` DATE NOT NULL ) ENGINE = MYISAM ; I want to write a general php script that get table name(test) from above query.
If you can access the string which gets queried before you run the query, you can do this:
preg_match("/^create table `(?P<tablename>)`/i", $query, $matches); print_r($matches); /* Output: Array ( [0] => CREATE TABLE `test` (`col1` INT( 10 ) NOT NULL ,`col2` VARCHAR( 50 ) NOT NULL , `col3` DATE NOT NULL ) ENGINE = MYISAM ; [tablename] => test [1] => test ) */ If you can't access the string for some reason, but you know that nothing is created in the database between the query and your code then you can use this query to retrieve the last created table:
SELECT * FROM information_schema.TABLES ORDER BY CREATE_TIME DESC LIMIT 1;