bind多参数

dwbf0jvd  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(338)

此查询有效

SELECT id, username, password 
        FROM users
       WHERE (email = ?)
        LIMIT 1"
$stmt->bind_param('s', $email);
        $stmt->execute();
        $stmt->store_result();

这不重要

SELECT id, username, password 
        FROM users
       WHERE (email = ? || username = ?)
        LIMIT 1"

需要同时使用电子邮件和用户名登录只有电子邮件登录有困难

7dl7o3gd

7dl7o3gd1#

使用或代替||

SELECT id, username, password 
        FROM users
       WHERE (email = ? OR username = ?)
        LIMIT 1
watbbzwu

watbbzwu2#

在声明参数时,可以列出所有类型,然后在其后列出变量,示例如下;

$sql = "SELECT id, username, password FROM users WHERE (email = ? OR username = ?) LIMIT 1"

$stmt->bind_param('ss', $email, $username);

此外,正如沙纳瓦兹所说,使用或代替| |。

相关问题