好像primary key 要设定吧(就像acess里没主键就不行一样)

解决方案 »

  1.   

    darkwing 说的对
    一个表必须有primary key
      

  2.   

    没必要必须有主键吧?
    你看看Phorum中的代码吧,老实说,我写了几个php站点,还没用到Create table
    我用的数据库是Postgres.
    喂,你的sql中是CREATE TABLE
      

  3.   

    好像,只有很低的版本的数据库才不需主键。
    Phorum里的建表也要primary key的!
    见db\mysql.php - create_table 函数!
      

  4.   

    用phpMyAdmin创建表和数据库是十分方便的!
      

  5.   

    我用下面的代码间表,成功了:
    <?
    require("./mysqlcon.php3");
    $db = new mysqlcon('localhost:/tmp/mysql.sock','root','1','test');
    $db->query('create table pk (id int)');
    ?>其中的mysqlcon.php3文件内容如下:<?
    class mysqlcon
    {
           var $con,$result,$row;
           var $debug = false;
           function mysqlcon($host,$user,$passwd,$db)
           {
            $this->con = mysql_connect($host,$user,$passwd);
            mysql_select_db ($db,$this->con);
           }
           
           function free()
           {
            if ($this->result) @mysql_free_result($this->result);
            mysql_close($this->con);
           }
           
           function query($cmd)
           {
            if ($debug) 
            {
            echo $cmd; 
            }
            if ($this->result) @mysql_free_result($this->result);
            $this->result = mysql_query($cmd,$this->con);
           }
           
           function fetch()
           {
            return ($this->row=mysql_fetch_object($this->result));
           }
           
           function result($field)
           {
            return $this->row->{$field};
           }
           
           function show($field)
           {
            echo $this->row->{$field};
            echo "&nbsp;";
           }
           
           function last_insert_id()
           {
            return mysql_insert_id($this->con);
           }
           
           function num_rows() 
           {
            return mysql_num_rows($this->result);
           }
           
           function seek($pos)
           {
            return mysql_data_seek($this->con,$pos);
           }

    ?>
      

  6.   

    我没有试验gzproger的程序是否正确,但是我觉得这么做是不是太麻烦了。
    我还是建议用PHPMYADMIN来建数据库和建表!
    如果大家没有可以邮给大家!
    但是gzproger的程序还是值得我参考的!
      

  7.   

    其实我那样等于直接写罢了。其实和ArchSh的并没有实质区别。ArchSh
    最好仔细看看,是不是建表的sql语句本身有错?你写的是creat,不是create,
    是不是这里错了?其实mysqlcon是我写的一个wrapper类来的,可以方便你使用mysql;
    例如$db->query(...);
       while ($db->fetch())
       {
              $db->show('my_field');
              .......
       }
    就可以执行查询和显示;不用关心资源的创建和释放;
    是不是比直接写方便多了。
      

  8.   

    去掉SQL语句最后的分号
    php中mysql_query($strQuery,$ndblink)里$strQuery最后好像是不能加分号的
    呵呵