小编Uar*_*ged的帖子

PHP json_decode不起作用

嗨,我想得到蒸汽用户的人物我已经存储了.json格式的文件中的数据.

{
"response": {
    "players": [
        {
            "steamid": "76561198137714668",
            "communityvisibilitystate": 3,
            "profilestate": 1,
            "personaname": "UareBugged",
            "lastlogoff": 1418911040,
            "commentpermission": 1,
            "profileurl": "http://steamcommunity.com/id/uarenotbest/",
            "avatar": "http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/da/daece8a16d866ef9bd03ddc4aa365c5862af1c21.jpg",
            "avatarmedium": "http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/da/daece8a16d866ef9bd03ddc4aa365c5862af1c21_medium.jpg",
            "avatarfull": "http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/da/daece8a16d866ef9bd03ddc4aa365c5862af1c21_full.jpg",
            "personastate": 1,
            "realname": "Michal Šlesár",
            "primaryclanid": "103582791436765601",
            "timecreated": 1400861961,
            "personastateflags": 0,
            "loccountrycode": "SK",
            "locstatecode": "08"
        }
    ]

}
Run Code Online (Sandbox Code Playgroud)

}

我想让personaname变为变量,但它什么都不做,变量是空的我认为json_decode不起作用,但我真的不知道.

    $pname = json_decode(file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v002/?key=KEYCONSORED&Steamids={$_SESSION['T2SteamID64']}"));
    echo $pname['response']['players']['personaname'];
Run Code Online (Sandbox Code Playgroud)

回声是空的

php json steam-web-api

5
推荐指数
1
解决办法
2366
查看次数

OOP MySQLi Connect

我是OOP的新手.我有班级数据库

class Database{
private $host;
private $user;
private $pass;
private $db;
public $mysqli;

function db_connect(){
    $this->host = 'localhost';
    $this->user = 'root';
    $this->pass = '';
    $this->db = 'db';

    $this->mysqli = new mysqli($this->host, $this->user, $this->pass, $this->db);
    return $this->mysqli;
}
Run Code Online (Sandbox Code Playgroud)

内部类数据库我有函数db_num

function db_num($sql){
    $num = mysqli_num_rows(mysqli_query($this->mysqli,"{$sql}"));
    return $num;
}
Run Code Online (Sandbox Code Playgroud)

但是当我在con参数$ this-> mysqli中使用时,它无法连接到数据库

php oop

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

php ×2

json ×1

oop ×1

steam-web-api ×1