欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 编程语言 > php >内容正文

php

php response body,数据库读写没问题,response body部分空 -凯发k8官方网

发布时间:2024/10/12 php 40 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 php response body,数据库读写没问题,response body部分空 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

求助~!文章操作这部分,_handlearticlelist(),使用 return时,response 的 body 部分为空,用print_r()能显示,代码照着视频中的敲的。user部分的注册就没问题,得到的response 的 body中有注册用户信息。谢谢!

getlist

```php

public function getlist($user_id,$page=1,$size=10){

if($size > 100) {

throw new exception('page limited 100', errorcode::page_limit_exceed);

}

$sql = 'select * from `article` where `user_id`=:user_id limit :limit, :offset';

$limit = ($page-1)*$size;

$limit = $limit < 0 ? 0 : $limit;

$stmt = $this->_db->prepare($sql);

$stmt->bindvalue(':user_id', $user_id);

$stmt->bindvalue(':limit', $limit);

$stmt->bindvalue(':offset', $size);

$stmt->execute();

$data = $stmt->fetchall(pdo::fetch_assoc);

//print_r($data);

return $data;

}

```

_handlearticlelist()

```php

private function _handlearticlelist(){

$user = $this->_userlogin($_server['php_auth_user'],$_server['php_auth_pw']);

$page = isset($_get['page']) ? $_get['page'] : 1;

$size = isset($_get['size']) ? $_get['size'] : 10;

if($size > 100){

throw new exception("page is too large", 400);

}

return $this->_article->getlist($user['user_id'], $page, $size);

}

private function _handlearticleview(){

}

private function _userlogin($php_auth_user, $php_auth_pw){

try{

return $this->_user->login($php_auth_user, $php_auth_pw);

}catch(exception $e){

if(in_array($e->getcode(),

[

errorcode::username_cannot_empty,

errorcode::password_cannot_empty,

errorcode::username_or_password_invalid

])) {

throw new exception($e->getmessage(), 400);

}

throw new exception($e->getmessage(), 500);

}

}

```

总结

以上是凯发k8官方网为你收集整理的php response body,数据库读写没问题,response body部分空的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

网站地图