以下mySql代码有什么问题?

时间:2013-07-18 13:58:25

标签: mysql decimal

以下是我编写过的最基本,最简单的代码,代码可能出错?

<?php
    $con=mysqli_connect("localhost","root","myroot","mydb");
    // Check connection
    if (mysqli_connect_errno())
      {
       echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    else
      {
       echo "Connecting to server Localhost succeeded ! ";
      }
    // Add column

    $sql="ALTER TABLE june2013 ADD time_interval (DECIMAL(5,2))";
    if (mysqli_query($con,$sql))
       {
        echo "Column added successfully";
       }
    else
       {
        echo "Error creating database: " . mysqli_error($con);
       }
    mysqli_close($con);
?>

我收到一条错误消息:

  

连接到服务器Localhost成功!创建数据库时出错:SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在第1行'(DECIMAL(5,2))'附近使用正确的语法

知道我为什么会这样做?

1 个答案:

答案 0 :(得分:1)

可能只是因为你在声明中缺少“COLUMN”吗?

$ sql =“ALTER TABLE june2013 ADD time_interval(DECIMAL(5,2))”;

应该是

$ sql =“ALTER TABLE june2013 ADD COLUMN time_interval DECIMAL(5,2)”;