슬림 프레임 워크를 사용하여 서버 데이터베이스에 대한 RESTful API를 구축하고 있습니다. 나는 왜 내 INSERT 문이 실행되지 않는지 알아 내려고 노력하고있다. 내가 실행할 때마다 "오류 : 참"과 "소리를 저장하지 못했습니다. 다시 시도하십시오."라는 응답이 표시됩니다. 메시지. 내 DB에 나타나지 않는다는 사실로이 오류를 확인했습니다. 내 API의 다른 INSERT 쿼리가 정상적으로 작동하고 있으며이 삽입 쿼리를 MySQL에서 자체적으로 실행 해 보았지만이 함수가 작동하지 않는 이유를 알 수 없습니다. 내 DBHandler 파일슬림 프레임 워크 INSERT 쿼리가 작동하지 않습니다.
:
public function newSound($user_id, $sound, $sound_viz, $latitude, $longitude, $location, $title) {
$response = array();
// Insert query
$stmt = $this->conn->prepare("INSERT INTO sounds (user_id, sound, sound_viz, latitude, longitude, location, title) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssddss", $user_id, $sound, $sound_viz, $latitude, $longitude, $location, $title);
$result = $stmt->execute();
$stmt->close();
// Check for successful insertion
if ($result) {
// Sound successfully inserted
return SOUND_CREATED_SUCCESSFULLY;
} else {
// Failed to post sound
return SOUND_CREATE_FAILED;
}
}
내 인덱스 파일에서 : 변수가 어떤 제안이나 조언이 SOUND_CREATED_SUCCESSFULLY 등이기 때문에
$app->post('/sounds/', function() use ($app) {
// check for required params
verifyRequiredParams(array('sound', 'sound_viz', 'latitude', 'longitude', 'location','title'));
$response = array();
$sound = $app->request->post('sound');
$sound_viz = $app->request->post('sound_viz');
$latitude = $app->request->post('latitude');
$longitude = $app->request->post('longitude');
$location = $app->request->post('location');
$title = $app->request->post('title');
global $user_id;
$db = new DbHandler();
// creating new sound
$sound_result = $db->newSound($user_id, $sound, $sound_viz, $latitude, $longitude, $location, $title);
if ($sound_result = SOUND_CREATED_SUCCESSFULLY) {
$response["error"] = false;
$response["message"] = "Sound saved successfully.";
$response['sound_id'] = $sound_id;
echoRespnse(201, $response);
} else {
$response["error"] = true;
$response["message"] = "Failed to save sound. Please try again.";
echoRespnse(200, $response);
}
});
내 DB 자격 증명이 올바른지? 감사!
'printf ("Error : % s. \ n", $ stmt-> error); ' –