如何解决这个问题,
我的表结构如下所示
CREATE TABLE
leave_histroy
(his_id
int(11)NOT NULL COMMENT ' histroy id auto increment',user_id
int(50)NOT NULL COMMENT' get 来自用户表ID',cl
double(4,2)NOT NULL COMMENT' casual 离开',sl
double(4,2)NOT NULL COMMENT' seak leave',el
double(4,2)NOT NULL COMMENT'赢得假期',mt
double(4,2)NOT NULL COMMENT'产假',pt
double(4,2)NOT NULL COMMENT '陪产假',lop
double(4,2)NOT NULL COMMENT'失去工资',compoff
double(4,2)NOT NULL COMMENT'补休假',
year
年(4)DEFAULT NULL COMMENT'存储假年',created_on
date DEFAULT NULL COMMENT'创建时间',created_by
varchar(100) NOT NULL COMMENT'由whome创建?',updated_on
日期DEFAULT NULL 评论'更新时间',updated_by
varchar(100)NOT NULL评论 '由谁更新?' )ENGINE = InnoDB DEFAULT CHARSET = latin1;
-insert function -
$query = "INSERT
INTO
`leave_histroy`(
`user_id`,
`cl`,
`sl`,
`year`,
`created_by`
)
VALUES(
:create_by,
:casual_leave,
:sick_leave,
:year,
:create_by
)";
try {
$result = $this->dbh->prepare($query);
$result->bindParam(":create_by", $leave_param['create_by']);
$result->bindParam(":casual_leave", $leave_param['casual_leave']);
$result->bindParam(":sick_leave", $leave_param['sick_leave']);
$result->bindParam(":year", $leave_param['year']);
$result->bindParam(":create_by", $leave_param['create_by']);
$result->execute();
return $result;
} catch (\PDOException $e) {
echo $e->getMessage();
die();
return false;
}
答案 0 :(得分:0)
将准备好的声明更改为此
$query = "INSERT INTO `leave_histroy`( `user_id`, `cl`, `sl`, `year`, `created_by`) VALUES(?,?,?,?)";
$query->bind_param("iiiis", $create_by, $casual_leave, $sick_leave, $year, $create_by);
try {
// set parameters and execute
$create_by = $leave_param['create_by']
$casual_leave = $leave_param['casual_leave']
$sick_leave = $leave_param['sick_leave']
$year = $leave_param['year']
$create_by = $leave_param['create_by']
//Execute Statement
$stmt->execute();
//return $result;
} catch (\PDOException $e) {
echo $e->getMessage();
die();
return false;
}