我目前在移动应用程序(前端)中工作,该应用程序使用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 ”中,我得到了错误,而且我不知道发生了什么。
他在PHP 5.5.12中使用WAMP服务器
我正在将Arch Linux 64位与LAMP与PHP 5.6.5一起使用。我在我的php.ini文件中同时启用了mysqli.so和pdo_mysql.so这两个扩展名。
我已经导入了与phpmyAdmin一起使用的数据库,该数据库包含与后端朋友相同的寄存器。
尽管如此,他仍然可以获取访问/ users路由的JSON数据,但我不能。
在此先感谢您的帮助。
代替
echo $response;
尝试
echo json_encode($response);
你不应该回显数组
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句