• 16-04-2010, 09:08:38
    #1
    <?
    function mysql2json($resultSet,$debug="false"){
        $numberRows=0;
        $arrfieldName=array();
        $json="{\n'data': [\n";
        while (false !==($meta = mysql_fetch_field($resultSet)))  {
            array_push(&$arrfieldName,$meta->name);
        }
    
        while($row=mysql_fetch_array($resultSet, MYSQL_NUM)) {
            $json.="{\n";
            for($r=0;$r < count($arrfieldName);$r++) {
                $json.="'".htmlspecialchars($arrfieldName[$r])."' : '".htmlspecialchars($row[$r])."',\n";
            }
            $json = trim($json,",\n");
    
            $json.="\n},\n";
        }
        $json = trim($json,",\n");
        $json.="]\n}";
    
        if($debug===true) {
            $json = "<pre>$json</pre>";
        }
        echo trim($json);
    }
    
    //Kullanımı
    
    $db = mysql_query("select * from veriler");
    mysql2json($db);
    
    //excode
    ?>
  • 16-04-2010, 09:40:19
    #2
    Üyeliği durduruldu
    json_encode fonksiyonuda alternatif olarak kullanilabilir