得到苗条框架的请求

I'm using the slim framework to build a restful web service. I have two tables with the following entries:

Table team
id_team    name
1          Brasil
2          England
3          Portugal

Table Person
id_pesorn id_team name     age ...
1          1       Rafinha 23  ...

and the following code:

require '../Slim/Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->response()->header('Content-Type', 'application/json;charset=utf-8');

$app->get('/person/team/:name/:team','getPerson');
$app->run();

function getConn(){
...
}

function getPerson($name, $team){
    $conn = getConn();
    $sql = "SELECT id_team FROM team WHERE name=:team";
    $stmt = $conn->prepare($sql);
    $stmt->execute();
    $pessoa = $stmt->fetchObject();

    $sql1 = "SELECT * FROM person WHERE id_team=".$pessoa->id_team."and name=:name";
    $stmt1 = $conn->prepare($sql1);
    $stmt1->bindParam("team", $team);
    $stmt1->bindParam("name", $name);
    $stmt1->execute();
    $pessoa1 = $stmt1->fetchObject();

    echo "{pessoas:".json_encode($pessoa1)."}";
}

when I call it by GET: localhost/services/pesorn/team/Rafinha/Brasil gives me a error:

Slim Application Error
Details

Type: ErrorException
Code: 2
Message: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
File: /Applications/XAMPP/xamppfiles/htdocs/aw014/webservice/services/index.php
Line: 38

but should return in JSON:

{"id_person":"1","id_team":"1","nome":"Rafinha","idade":"23",...}

I don't know what I'm doing wrong. Could anyone help me. Thanks.

douyong2531
douyong2531 而不是绑定param,你不在第一个“团队”中进行查询,无论如何。使用:$stmt->execute(array(':team'=>$team));注意键上的前导':'。有用的链接:12344741/binding-multiple-values-in-pdo
6 年多之前 回复
dqrsceg6279196
dqrsceg6279196 只需使用$stmt1->bindParam(“:name”,$name);.$stmt1->bindParam(“team”,$team);没有绑定任何东西,所以你可以删除它。您可以在doc页面上看到这个以及更多内容:php.net/manual/en/pdostatement.bindparam.php
6 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐