AngularJS POST在带有PHP内部错误500的SQLite数据库上


AngularJS POST on SQLite DB with PHP Internal Error 500

我正在AngularJS中使用SQLite作为本地DB构建一个应用程序。连接是通过PHP实现的。我可以读取数据,也可以添加数据,但当我想删除数据时,我会收到500内部错误。以下代码是我在项目中使用的代码。

app.js

$scope.remove = function() {
        var removeIds = helperFactory.filterFiledArrayByDone($scope.items, 'id', 1);
        if (removeIds.length > 0) {
            $http({
                method : 'POST',
                url : urlRemove,
                data : "ids=" + removeIds.join('|'),
                headers : {'Content-Type' : 'application/x-www-form-urlencoded'}
            })
                .success(function(data){
                    if (_recordRemovedSuccessfully(data)){
                        $scope.items = $scope.items.filter(function(item) {
                            return item.done == 0;
                        });
                    }
                })
                .error(function(data, status, headers, config){
                    throw new Error('Something went wrong with removing')
                });
        }
    };

remove.php

<?php
try {
    if (empty($_POST['ids'])) {
        throw new PDOException("Invalid Request";
    }
    $ids = $_POST['ids'];
    $idsArray = explode('|', $ids);
    $placeholders = implode(', ', array_fill(0, count($idsArray), '?'));
    $objDb = new PDO('sqlite:../database/database');
    $objDb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "DELETE FROM 'items'
            WHERE 'id' IN ({$placeholders})";
    $statement = $objDb->prepare($sql);
    if (!$statement->execute($idsArray)) {
        throw new PDOException("The execute method failed");
    }
    echo json_encode(array(
        'error' => false
        ), JSON_HEX_TAG| JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
} catch(PDOException $e){
    echo json_encode(array(
        'error' => true,
        'message' => $e->getMessage()
        ), JSON_HEX_TAG| JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
}

index.html

<div class="columns">
                    <div class="flr">
                        <button type="button" class="small button primary" ng-click="remove()"><i class="fa"></i>Remove</button>    
                    </div>
                </div>

控制台.log

angular.js:9866 POST http://localhost:8888/mod/remove.php 500 (Internal Server Error)
angular.js:11655 Error: Something went wrong with removing
    at app.js:199
    at angular.js:9415
    at processQueue (angular.js:13248)
    at angular.js:13264
    at Scope.$get.Scope.$eval (angular.js:14466)
    at Scope.$get.Scope.$digest (angular.js:14282)
    at Scope.$get.Scope.$apply (angular.js:14571)
    at done (angular.js:9698)
    at completeRequest (angular.js:9888)
    at XMLHttpRequest.requestLoaded (angular.js:9829)

有人知道怎么解决这个问题吗?

也许我错了,这不是问题所在,但你在这里错过了一个")":

if (empty($_POST['ids'])) {
    throw new PDOException("Invalid Request";
}