使用PDO PHP的PostGreSQL CREATE TABLE

Mac*_*nie 1 php postgresql pdo

我尝试在我的PostgreSQL数据表中执行一个简单的创建表,通过执行下面的createTables函数:

    public function createTables() {
        try {
            $db = new PDO('pgsql:host='.$this->PARAM_hote.';port='.$this->PARAM_port.';dbname='.$this->PARAM_nom_bd.';user='.$this->PARAM_utilisateur.';password='.$this->PARAM_mot_passe);

            $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

            $sql ='CREATE TABLE IF NOT EXISTS test (id INT(11) AUTO_INCREMENT PRIMARY KEY, prename VARCHAR(50) NOT NULL);';
            $db->exec($sql);
        } catch(PDOException $e) {
            echo $e->getMessage();
        }
    }
Run Code Online (Sandbox Code Playgroud)

但我仍然有:

testSQLSTATE[42601]: Syntax error: 7 ERREUR: erreur de syntaxe sur ou près de « ( » LINE 1: CREATE TABLE IF NOT EXISTS test (id INT(11) AUTO_INCREMENT P... ^ 
Run Code Online (Sandbox Code Playgroud)

我不知道为什么?...

感谢帮助

Clo*_*eto 5

postgresql中没有自动增量.而是使用serial.并且integer类型总是4个字节.

test (id serial PRIMARY KEY,
Run Code Online (Sandbox Code Playgroud)

serial类型表示带not null约束的整数和附加序列.

http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL