使用一个具有可变数量的输入var的bind_param() [英] Use one bind_param() with variable number of input vars

查看:34
本文介绍了使用一个具有可变数量的输入var的bind_param()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试像这样使用变量绑定:

I try to use variable binding like this:

$stmt = $mysqli->prepare("UPDATE mytable SET myvar1=?, myvar2=... WHERE id = ?")) {
$stmt->bind_param("ss...", $_POST['myvar1'], $_POST['myvar2']...);

但是某些$ _POST ['...']可能为空,所以我不想在数据库中更新它们.

but some of the $_POST['...'] might be empty so I don't want to update them in the DB.

考虑空$ _POST ['...']的所有不同组合是不切实际的,尽管我可以根据需要构建字符串"UPDATE mytable SET ...",但bind_param()是不同的野兽.

It's not practical to take into account all the different combination of empty $_POST['...'] and although I can build the string " UPDATE mytable SET..." to my needs, bind_param() is a different beast.

我可以尝试将其调用构建为字符串并在其上使用eval(),但感觉不正确:(

I could try building its call as a string and use eval() on it but it doesn't feel right :(

推荐答案

您可以使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆