Php rest api身份验证错误SQLSTATE[HY093]

Php rest api身份验证错误SQLSTATE[HY093],php,api,rest,Php,Api,Rest,此部分使用身份验证功能 <?php $authentication = function() { try{ $app=\slim\slim:: getInstance(); $user= $app->request-> headers ->get('HTTP_USER'); $pass= $app->request-> headers ->get('HTTP_PASS'); $pass= sha1($pass); $connection= g

此部分使用身份验证功能

<?php
$authentication = function()
{   try{
$app=\slim\slim:: getInstance();
$user= $app->request-> headers ->get('HTTP_USER'); 
$pass= $app->request-> headers ->get('HTTP_PASS'); 
$pass= sha1($pass);


$connection= getconnection();
$dbh= $connection-> prepare(" SELECT*  FROM keys where user=? AND pass=? ");

$dbh->execute();
$users= $dbh-> fetchAll(PDO::FETCH_OBJ);


//print_r($users);
$app-> response->headers->set("content-type","application/json");
$app-> response->status(800);
$app-> response->body(Json_encode($users));

if ($authentication === false)
 {
$app->halt(401);
 }
    }
catch(PDOexception $e)
    {
    echo"error". $e-> getmessage();
    }   
};  

在这里,您不是以传统的方式使用准备好的语句

把这行代码放到你的代码中,我认为它会很好地工作

$connection= getconnection();
$dbh= $connection-> prepare(" SELECT*  FROM keys where user=:user AND pass=:pass");
$dbh->bindParams(':user',$user);
$dbh->bindParams(':pass',$pass);

$dbh->execute();
$users= $dbh-> fetchAll(PDO::FETCH_OBJ);
您的方法也可以工作,但需要在
execute()
中发送一个数组作为参数。在。

中显示了对未定义的方法PDOStatement::bindParams()的调用

代码在这里

$authentication = function()
{   try{
$app=\slim\slim:: getInstance();
$user= $app->request-> headers ->get('HTTP_USER'); 
$pass= $app->request-> headers ->get('HTTP_PASS'); 
$pass= sha1($pass);


$connection= getconnection();
$dbh= $connection-> prepare(" SELECT*  FROM keys where user=:user AND      pass=:pass");
$dbh->bindParams(':user',$user);
$dbh->bindParams(':pass',$pass);

$dbh->execute();
$users= $dbh-> fetchAll(PDO::FETCH_OBJ);
$authentication = function()
{   try{
$app=\slim\slim:: getInstance();
$user= $app->request-> headers ->get('HTTP_USER'); 
$pass= $app->request-> headers ->get('HTTP_PASS'); 
$pass= sha1($pass);


$connection= getconnection();
$dbh= $connection-> prepare(" SELECT*  FROM keys where user=:user AND      pass=:pass");
$dbh->bindParams(':user',$user);
$dbh->bindParams(':pass',$pass);

$dbh->execute();
$users= $dbh-> fetchAll(PDO::FETCH_OBJ);