星期四, 11月 11, 2010

MYSQL直接輸出JSON

 
 
透過SQL語法直接使用MYSQL輸出JSON
下的語法 
 
 
SELECT 
     CONCAT("[",
          GROUP_CONCAT(
               CONCAT("{username:'",username,"'"),
               CONCAT(",email:'",email),"'}")
          )
     ,"]") 
AS json FROM users;
 
輸出結果

[
     {username:'tommy',email:'tommy@tommysplace.com'},
     {username:'jane',email:'jane@examples.com'},
     {username:'jack',email:'jack@jiford.com'}
]