代码之家  ›  专栏  ›  技术社区  ›  Burhan

Mysql返回带有键和Tabelle名称的数组-删除键

  •  -1
  • Burhan  · 技术社区  · 7 年前

      $db = $db->first("SELECT * FROM devices LEFT JOIN customer ON devices.customerid = customer.customerid WHERE devices.hash = '".$hash."' OR devices.deviceid = '".$hash."'");
    

    使用此功能:

        //Select Datenbankanfrage, erste Zeile
    function first($query, $restype=0) {
        $this->querystring = $query;
    
        if ( $restype==1 ) $restype=MYSQLI_ASSOC;
        else $restype=MYSQLI_BOTH;
    
        $result = $this->query($query); //Query
        if ( !$result ) return false;
    
        $row = $result->fetch_array($restype);
        $result->free();
    
        return $row;
    }
    

    但我收到一封 array 以按键作为响应:

    1 => Maxii
    Name => Maxii
    2 => Streetfromthe
    Street => Streetfromthe
    

    如何禁用键(1,2)或如何在数组中删除它?

    https://nopaste.xyz/?23ccf318bbfc93fb#Oes85/9Z8+Kookk2nTLmbtObjaL8mD2aitPPrHV3v9w=

    2 回复  |  直到 7 年前
        1
  •  1
  •   Salketer    7 年前

    负责更改重新类型的行包括:

    if ( $restype==1 ) $restype=MYSQLI_ASSOC;
        else $restype=MYSQLI_BOTH;
    
        2
  •  0
  •   André Catita    7 年前

    你需要替换为 $result->fetch_array $result->fetch_assoc

    编辑:在您的情况下,将其保留在fetch_数组中,并使用您拥有的函数。 first($sql, 1);