我在将数据从php插入数据库时遇到问题。
档案是: Patient.php
表名是: patient_tbl
内表是:头像和教育
这里是插入代码: 以下代码没有问题,'education'的值将被插入到表
$sql = "INSERT INTO " . $this->_table;
$sql .= "education,";
$params = array(
urlencode($patient->getEducation()),
);
return $this->exec($sql, $params);
}
但现在这是我的问题, “阿凡达”不插入表格
错误消息为:“无法准备查询。”
$sql = "INSERT INTO " . $this->_table;
$sql .= "education, avatar, ";
$params = array(
urlencode($patient->getEducation()),
urlencode($patient->getAvatar()),
);
return $this->exec($sql, $params);
}
我的问题是什么?我无法找到解决方案,。
我非常感谢你的帮助。
谢谢
答案 0 :(得分:1)
基本语法sql查询'INSERT'是
INSERT [INTO] tbl_name [(col_name,...)]
VALUES (expression,...),(...)
如果使用某些参数,则需要添加括号:
$sql = "INSERT INTO " . $this->_table;
$sql .= "(education, avatar) VALUES (?, ?)";
$params = array(
urlencode($patient->getEducation()),
urlencode($patient->getAvatar()),
);
return $this->exec($sql, $params);
}
然后写一下$ this-> exec?