php mysql更新从表单值生成语句
我正在创建一个非常小的数据库抽象层,我想发送从表单获得的变量数组,并生成更新sql语句,并最终执行它。 我应该在下面倒数第二行放什么? 例如。
$table name = "user";
$username = $_post['username'];
$password = $_post['password'];
$email = $_post['email'];
$array = (username=>$username, password=>$password, email=>$email);
$query = "update $this->tableName".
$query = """" The value from the assc array in the form of database value='form value'
$query = "WHERE condition";
I am creating a very small database abstract layer, i want to send an array of variables that i obtained from a form, and generate an update sql statement, and eventually execute it. What do I put on the second to last line below?
for example.
$table name = "user";
$username = $_post['username'];
$password = $_post['password'];
$email = $_post['email'];
$array = (username=>$username, password=>$password, email=>$email);
$query = "update $this->tableName".
$query = """" The value from the assc array in the form of database value='form value'
$query = "WHERE condition";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
foreach()
循环从数组生成查询子句。请注意,您需要使用array()
构造声明数组,并引用关联键。You can use a
foreach()
loop to generate your query clause from your array. Note that you need to declare your array with thearray()
construct, and quote your associative keys.您可以使用类似的内容:
但您需要处理特殊情况,例如当值为 null 或日期时
You can use something like:
but you need to take care of special cases, for example when the value is null or a date