我在 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/