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.