[英]inserting data from php to database mysql table
我在将数据从php插入数据库时遇到问题。
文件是: Patient.php
表名称是: Patient_tbl
表格内部是: 头像和教育
这是插入代码: 以下代码没有问题,“教育”的值将插入到表中
$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);
}
我有什么问题? 我找不到解决方案。
非常感谢您的帮助。
谢谢
基本语法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中是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.