How to add new column to MYSQL table?

后端 未结 8 1728
南旧
南旧 2020-11-27 12:38

I am trying to add a new column to my MYSQL table using PHP. I am unsure how to alter my table so that the new column is created. In my assessment table I have:



        
8条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 13:42

    Something like:

    $db = mysqli_connect("localhost", "user", "password", "database");
    $name = $db->mysqli_real_escape_string($name);
    $query = 'ALTER TABLE assesment ADD ' . $name . ' TINYINT NOT NULL DEFAULT \'0\'';
    if($db->query($query)) {
        echo "It worked";
    }
    

    Haven't tested it but should work.

提交回复
热议问题