heldenbrau Posted September 1, 2009 Share Posted September 1, 2009 I want to check if a table exists and if it doesn't then create it. I have tried this code: $sql = "SELECT * FROM mythreads$username"; if ($mysqli->query($sql)===TRUE){ } else{ $sql = "CREATE TABLE mythreads$username (heading VARCHAR(100) NOT NULL, casenum INT(20) NOT NULL, lastpost INT(20) NOT NULL, replies INT(10) NOT NULL, type INT(1) NOT NULL)"; if ($mysqli->query($sql))===TRUE{ }else die("could not create database" . $mysqli->error); } But I get Parse error: syntax error, unexpected T_IS_IDENTICAL Link to comment https://forums.phpfreaks.com/topic/172757-create-table-if-it-doesnt-exist/ Share on other sites More sharing options...
waynew Posted September 1, 2009 Share Posted September 1, 2009 CREATE TABLE IF NOT EXISTS tablename( id INT(11) NOT NULL AUTO_INCREMENT, etc Link to comment https://forums.phpfreaks.com/topic/172757-create-table-if-it-doesnt-exist/#findComment-910562 Share on other sites More sharing options...
heldenbrau Posted September 1, 2009 Author Share Posted September 1, 2009 That looks like a better way, but still getting the same error message. What does the error message mean? Link to comment https://forums.phpfreaks.com/topic/172757-create-table-if-it-doesnt-exist/#findComment-910584 Share on other sites More sharing options...
waynew Posted September 1, 2009 Share Posted September 1, 2009 Show your code. Link to comment https://forums.phpfreaks.com/topic/172757-create-table-if-it-doesnt-exist/#findComment-910587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.