She*_*shi 5 php mysql codeigniter
我正在使用codeigniter而我正在尝试将以下查询转换为dbforge样式查询,我该怎么办?
create table filter (
filterid int primary key auto_increment,
filtername varchar(50) not null,
categoryid int not null,
isactive tinyint not null,
sequence int not null,
foreign key(categoryid) references category(id));
Run Code Online (Sandbox Code Playgroud)
col*_*ick 10
以下是4种方法.前三个使用create_table和第四个可以在稍后添加字段时完成.
$this->dbforge->add_field('id INT NOT NULL AUTO_INCREMENT PRIMARY KEY');
$this->dbforge->add_field('CONSTRAINT FOREIGN KEY (id) REFERENCES table(id)');
$this->dbforge->add_field('INDEX (deleted)');
$this->dbforge->add_column('table',[
'COLUMN id INT NULL AFTER field',
'CONSTRAINT fk_id FOREIGN KEY(id) REFERENCES table(id)',
]);
Run Code Online (Sandbox Code Playgroud)
$this->db->query();代替使用。
这总是对我有用......
$sql="create table filter (
filterid int primary key auto_increment,
filtername varchar(50) not null,
categoryid int not null,
isactive tinyint not null,
sequence int not null,
foreign key(categoryid) references category(id))";
$this->db->query($sql);
Run Code Online (Sandbox Code Playgroud)