[英]PostGreSQL CREATE TABLE with PDO PHP
I try to do a simple create table in my PostgreSQL datatable, by executing the createTables function bellow: 我尝试通过执行下面的createTables函数在PostgreSQL数据表中创建一个简单的创建表:
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();
}
}
But I still have: 但是我仍然有:
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... ^
And I don't know why ?... 而且我不知道为什么吗?...
Thanks for help 感谢帮助
There is no autoincrement in postgresql. postgresql中没有自动增量。 In instead use serial
. 相反,使用serial
。 And the integer
type is always 4 bytes. integer
类型始终为4个字节。
test (id serial PRIMARY KEY,
The serial
type implies integer with a not null
constraint and an attached sequence. serial
类型表示具有not null
约束和附加序列的整数。
http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.