我试图在laravel代码中创建一个临时表,插入值并在前端打印一些内容。但是我的临时表没有创建。
$temEmployee = DB::insert(DB::raw("CREATE TEMPORARY TABLE IF NOT EXISTS tmpEmp(
tmpid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
NIC varchar(100),
Designation varchar(100),
WorkPlace varchar(100),
Initials varchar(100),
LastName varchar(100),
DOB DATE,
Mobile varchar(10),
FirstAppoinment DATE,
DutyAssumeDate DATE
)"));
我的代码有问题吗?
答案 0 :(得分:1)
使用DB::statement();
而非DB::insert();
执行create table query
$temEmployee = DB::statement("CREATE TEMPORARY TABLE IF NOT EXISTS tmpEmp(
tmpid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
NIC varchar(100),
Designation varchar(100),
WorkPlace varchar(100),
Initials varchar(100),
LastName varchar(100),
DOB DATE,
Mobile varchar(10),
FirstAppoinment DATE,
DutyAssumeDate DATE
)");