Jump to content

Create table if it doesn't exist


heldenbrau

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.