$con = @odbc_connect($dsn,"","") or die("连接出错!");$con = odbc_connect($dsn,"","") or die("连接出错!");

解决方案 »

  1.   

    把:$t = odbc_exec($con,"INSERT INTO my_class(id,name,major,xy,class) VALUES ('1','1','1','1','1');" );改为:$t = odbc_exec($con,"INSERT INTO my_class(id,name,major,xy,class) VALUES ('1','1','1','1','1')");因为,你在INSERT 语句的后面多加了个 ; ------------------------------------------------------------
    http://kmok.cn
      

  2.   

    连接上没有什么问题,因为通过select可以读取数据.如果改成
    $t = odbc_exec($conn,"INSERT INTO my_class(id,name,major,xy,class) VALUES ('1','1','1','1','1')");
    则输出:
    Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] 操作必须使用一个可更新的查询。, SQL state S1000 in SQLExecDirect in D:\MyWebRoot\2.php on line 4
    而line 4就是对应上面的代码,请问这个是怎么回事,谢谢
      

  3.   

    $dsn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=db1.mdb";
    $con = @odbc_connect($dsn,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!");$table = "my_class"; // 要插入的表
    $field = "id,name,major,xy,class"; //要插入的数据字段
    $varlue= "'1','1','1','1','1'"; //对应字段所对应的值$sql =  "INSERT INTO $table ($field) VALUES ($varlue)";
    $query= @odbc_do($con,$sql);
    odbc_close($con);echo $sql; //测试sql检查字段输入是否正确, 可以试着将sql语句输出, 直接打开数据库用输出的sql语句进行测试