mysqli语句execute(),正确的方法 [英] mysqli statement execute(), the right way

查看:861
本文介绍了mysqli语句execute(),正确的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MyFile.php中有此代码

I have this code in 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
)
);

来自MySQL的错误消息

Error Message from MySQL

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

我花了几个小时尝试解决此问题,但我没有.

I have spent a few hours to try to fix this but I could not.

有帮助吗?

推荐答案

您需要在执行查询之前绑定参数, 以程序方式做到

you need to bind params before executing the query, in procedural way do like this

mysqli_stmt_execute($stmt);

如果您在绑定参数后以面向对象的方式进行操作

if you are doing it like object oriented way after binding params

/* Execute the statement */
$stmt->execute();

文档链接.

http://www.php.net/manual/zh/mysqli-stmt.execute.php

这篇关于mysqli语句execute(),正确的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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