PHP + MySQL,添加列并填写

时间:2019-03-14 14:01:17

标签: php mysql

我有PHP代码:

model_poisson_training<- glm(training_m ~ training_X, family="poisson")
summary(model_poisson_training)
coef.poisson<-model_poisson_training$coefficients

我正在尝试在表中添加一列(如果不存在),并立即用相同的日期(2000-12-02)将所有添加的行填充到此添加的列中。 但是我认为这段代码有问题:

$link_multiq = mysqli_connect($host, $user, $password, $dbname);
mysqli_set_charset($link_multiq, "utf8");

$sql = 'SET @preparedStatement = (SELECT IF(
    (SELECT COUNT(*)
    FROM INFORMATION_SCHEMA.COLUMNS
     WHERE table_name = "ring" 
     AND table_schema = "test1_serv" 
     AND column_name = "date_make_count"
     ) > 0, 
     "SELECT 1;", 
     "ALTER TABLE ring ADD date_make_count DATE;UPDATE ring SET date_make_count = '2000-12-02';"
     )); 
     PREPARE alterIfNotExists FROM @preparedStatement; 
     EXECUTE alterIfNotExists; 
     DEALLOCATE PREPARE alterIfNotExists;';

mysqli_multi_query($link_multiq, $sql);     
mysqli_close($link_multiq);

我不知道如何正确编写此部分。我尝试过:

...UPDATE ring SET date_make_count = '2000-12-02';

和其他方式,但是不起作用。 请帮忙!

0 个答案:

没有答案