-1
public function deleteComment( $id, $check_author = true ) {
        $q = $this -> database -> prepare( "SELECT `id`, `aid` FROM `addon_comments` WHERE `id` = :id" );
        $q -> execute( array( 'id' => $id ) );

        if( !$q -> rowCount( ) )
            return -1;

        $r      = $q -> fetch( );
        $uid    = $this -> registry -> getClass( 'Users' ) -> isLogged( );

        if( $check_author && $r[ 'aid' ] != $uid )
            return -2;


        $s = $this -> database -> prepare( "DELETE FROM `addon_comments` WHERE `id` = :id OR `parent` = :id" );
        $s -> execute( array( 'id' => $id ) );

        return 1;           
    }

函数返回给我-1,但查询删除了行。当我评论删除查询时,一切正常(函数返回1)。我做错了什么?

4

1 回答 1

0

如果成功选择了一行,下面的代码将返回 true:

if( $q -> rowCount( ) )
    return -1;

我建议如果您想检查否定结果并让它返回-1,请使用:

if($q->rowCount() < 1)
    return -1;
于 2013-10-18T12:00:30.310 回答