带有Json问题的PHP数组

I want to achieve this using my php script:

{  
    "aaData":[  
        [  
            "100",
            "189",
            "2"
        ],
        [  
            "100",
            "189",
            "1"
        ],
        [  
            "100",
            "188",
            "4"
        ],
        [  
            "100",
            "188",
            "3"
        ],
        [  
            "100",
            "188",
            "2"
        ]
    ]
}

I am fetching data from database, and i want to put results to above format. Query looks like this:

SELECT user_id, module_id, action_id FROM test;

Please help me to put results of these 3 columns on format which i mentioned above.

Regards

Using PDO, you can do:

$result = $conn->execute("SELECT `user_id`, `module_id`, `action_id` FROM `test`");
$rows = $result->fetchAll(PDO::FETCH_NUM);
echo json_encode(array('aaData' => $rows));

fetchAll returns a 2-dimensional array of the results of the query. The PDO::FETCH_NUM mode makes the rows of these results be numerically-indexed arrays. Then we put this into the aaData element of another array, and convert it to JSON.