Slim中的PDO查询导致PHP致命错误:未捕获RuntimeException:输出缓冲区中的意外数据

时间:2016-12-28 18:41:01

标签: php pdo slim

所以我的基本苗条应用就是这样:

<?php
session_start();

if (!file_exists( __DIR__ . '/settings.php')) { die("Error 500: application configuration problem."); }
require __DIR__ . '/../vendor/autoload.php';

$config = require __DIR__ . '/settings.php';
$app = new \Slim\App($config);

$container = $app->getContainer();

$container['s4s'] = function ($container) {
    $db = $container['settings']['s4s'];
    return new PDO('sqlsrv:Server='.$db['host'].';Database='.$db['database'], $db['username'], $db['password']);
};

$app->get('/ff', function ($request, $response) {

        $sql = 'SELECT "dbo"."ZAKAZKA"."ZAKAZKA ID" FROM "dbo"."ZAKAZKA" WHERE ("ZAKAZKA ID" LIKE \'1216%\' ) ORDER BY "dbo"."ZAKAZKA"."ZAKAZKA ID"  DESC';
        $stmt = $this->s4s->prepare($sql);

        if($stmt->execute()){
            echo $stmt->debugDumpParams();
            $results=$stmt->fetchAll();
        }

  });

这很好用,花花公子。如果我将查询代码移动到控制器

<?php

namespace Glued\Playground;
use \PDO;
use Glued\Controllers\Controller;


class pdo_test extends Controller
{
    public function test($request, $response)
    {
        $sql = 'SELECT "dbo"."ZAKAZKA"."ZAKAZKA ID" FROM "dbo"."ZAKAZKA" WHERE ("ZAKAZKA ID" LIKE \'1216%\' ) ORDER BY "dbo"."ZAKAZKA"."ZAKAZKA ID"  DESC';
        echo $sql;
        $stmt = $this->container->s4s->prepare($sql); // this line breaks things
        if($stmt->execute()){
            echo $stmt->debugDumpParams();
            $results=$stmt->fetchAll();
        }

    }    
}

并添加到主代码

$app->get('/playground/fff', '\Glued\Playground\Pdo_test::mytest');

它开始在$ stmt赋值中断,错误

PHP致命错误:未捕获RuntimeException:输出缓冲区中的意外数据。也许你在开始敲定之前有字符(对象(Slim \ Http \ Response))\ n#1 /opt/Web/html/glued/vendor/slim/slim/Slim/App.php(298):Slim \ App- &gt;进程(对象(Slim \ Http \ Request),对象(Slim \ Http \ Response))\ n#2 /opt/Web/html/glued/public/index.php(4):Slim \ App-&gt;在第552行的/opt/Web/html/glued/vendor/slim/slim/Slim/App.php中抛出run()\ n#3 {main} \ n

因为这不适用于我写的其他控制器,我要么忽略了明显的东西,要么PDO(我通常不会使用)导致过早输出。不知道如何调试它。

非常欢迎提示和解决方案,提前感谢!

注意:我通常也不使用mssql,但我遇到了与mysql db相同的问题。

0 个答案:

没有答案