未捕获的PDOException:SQLSTATE [21000]:基数违规:1241操作数应包含1列

时间:2016-05-15 08:48:44

标签: mysql

我得到的错误就像 未捕获的PDOException:SQLSTATE [21000]:基数违规:1241操作数应包含1列

if ($_POST['submit'] ?? '' == "Log In") {

    $query = "SELECT * FROM member WHERE (email, password) LIKE (:email, :password)";

    $stmt = $link -> prepare($query);
    $stmt -> bindValue(':email', $_POST['loginemail'], PDO::PARAM_STR);
    $stmt -> bindValue(':password', md5(md5($_POST['loginemail']).$_POST['loginpassword']), PDO::PARAM_STR);
    $stmt -> execute();
    $rows = $stmt -> fetchAll();

}

但是这句话中没有错误。

$sql = "SELECT ko_name FROM dogBREEDS WHERE dogBREEDS.ko_name LIKE (:keyword) ORDER BY id ASC LIMIT 0, 10";
$query = $pdo->prepare($sql);
$query->bindParam(':keyword', $keyword, PDO::PARAM_STR);
$query->execute();
$list = $query->fetchAll();

我该如何解决这个问题?和差异是什么?

2 个答案:

答案 0 :(得分:0)

  

$query = "SELECT * FROM member WHERE (email, password) LIKE (:email, :password)";

这个sql在正确的语法中不是正确的sql。 LIKE(或看看这里MySQL LIKE Clause)不能像这样使用,请试试这个;)

$query = "SELECT * FROM member WHERE email LIKE (:email) and password LIKE (:password)";

答案 1 :(得分:0)

我刚刚改变了这个。

$query = "SELECT ID FROM member WHERE email=:email AND password=:password";

$stmt = $link -> prepare($query);
$stmt -> bindParam(':email', $_POST['loginemail'], PDO::PARAM_STR);
$stmt -> bindValue(':password', md5(md5($_POST['loginemail']).$_POST['loginpassword']), PDO::PARAM_STR);
$stmt -> execute();