Php 超薄应用程序错误。代码8:数组到字符串的转换

Php 超薄应用程序错误。代码8:数组到字符串的转换,php,mysql,pdo,mysqli,slim,Php,Mysql,Pdo,Mysqli,Slim,我目前在一个移动应用程序(前端)中工作,该应用程序使用PDO从MySQL数据库通过Php Slim后端提供一些数据。这个(后端)是由一个队友开发的,在他的电脑上就像一个魔咒 有一个GET路由应该返回一些JSON数据: $app->get('/users', function () { require_once 'controllers/User.php'; $user = new User(); $user->setJsonMode(true); $user

我目前在一个移动应用程序(前端)中工作,该应用程序使用PDO从MySQL数据库通过Php Slim后端提供一些数据。这个(后端)是由一个队友开发的,在他的电脑上就像一个魔咒

有一个GET路由应该返回一些JSON数据:

$app->get('/users', function () {
   require_once  'controllers/User.php';
   $user = new User();
   $user->setJsonMode(true);
   $user->setJoin('default');
   $user->setSelect('user_id, user.role_id, role, name,
                     userName, email, picture, user.last_update');
   echo $user->select();
});
“用户”控制器作为所有控制器从“CtrlDB”控制器继承

如果我尝试访问“api/users”,我会得到:

类型:ErrorException 代码:8 消息:数组到字符串转换 文件:/home/shy-n/projects/tienda/api/controllers/CtrlDB.php 第32行

线路32位于CtrlDB建造商处:

public function __construct($table,$fields,$idProperty,$relations) {
    $dsn = DB_ENGINE.':host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8';
    try {
        $this->db = new PDO($dsn, DB_USERNAME, DB_PASSWORD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
    } catch (PDOException $e) {
         $response = $this->response("error","Connection failed: " . $e->getMessage(),null);
         echo $response;
         exit;
    }

    $this->table = $table;
    $this->idProperty = $idProperty;
    $this->fields = $fields;
    $this->relations = $relations;
    $this->start = 0;
    $this->limit = 25;
    $this->select = "`".implode("`, `",$fields)."`";
}
在“echo$response”中,我得到了错误,我不知道发生了什么

他在PHP5.5.12中使用WAMP服务器

我在PHP5.6.5中将Arch Linux 64位与LAMP一起使用。我已经启用了这两个扩展 mysqli.sopdo_mysql.so在我的php.ini文件中

我已经导入了与phpmyAdmin一起使用的数据库,其中包含与后端中的朋友相同的寄存器

尽管如此,他仍然可以获得访问/users路由的JSON数据,但我不能

提前感谢您的帮助。

代替

  echo $response;
试一试


你不应该呼出数组

嗯,是的。我刚刚使用了print_r($response),看到捕获到的PDO异常错误,结果是我们不同的DB_用户和DB_密码配置。。。沟通问题,终于解决了问题。
  echo json_encode($response);