php - mysqli_stmt::execute() 期望正好有 0 个参数,给定 1 个

标签 php mysqli

我在 MyFile.php 中有这段代码

$db= mysqli_connect("host","user","pw","db");//connect to db
if (mysqli_connect_errno($con))//check connection
{echo "Failed to connect to MySQL: " . mysqli_connect_error();}
//Create a token for the unique link
$title= $_GET[apt_title];
$email= $_GET[mail_address];
$token = sha1(uniqid($email, true));
$time = $_SERVER["REQUEST_TIME"];
//prepare the query to be executed
$query = $db->prepare(
"INSERT INTO pending_users (email, token, title_apt, tstamp) VALUES (?, ?, ?, ?)"
);
$query->execute(
array(
    $title,
    $email,
    $token,
    $time
)
);

错误信息:

Warning: mysqli_stmt::execute() expects exactly 0 parameters, 1 given in /websites

我应该如何正确调用 execute()

最佳答案

因为 mysqli::execute() 不接受任何参数。在调用它之前,您必须准备查询,然后将参数绑定(bind)到查询。然后你必须调用 execute() 方法。所以像这样尝试:

$query = $db->prepare(
"INSERT INTO pending_users (email, token, title_apt) VALUES (?, ?, ?, ?)"
);
$query->bind_param('ssss', $title, $email, $token, $time);
$query->execute();

有关更多信息,请查看 documentation

关于php - mysqli_stmt::execute() 期望正好有 0 个参数,给定 1 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19707088/

相关文章:

php - 这两行PHP代码是什么意思?

mysql - mysqli连接仅在硬编码时有效

php - MySQL查询返回所有字段而不是过滤

php - 更改选择取决于输入值

php - 带有 php while 循环的 Jquery 动态选择器

php - 从数据库更改 googlemap 标记图像

php - MySQL中如何通过order by id获取数据

javascript - 使用 PHP 创建动态过滤器列表 使用 JS 搜索它们

php - 将 SQL 列中的每个项目选择到一个数组中,PHP

php - 在交易过程中重新加载页面