In lines like this:
$sql="SELECT `cid`,`name`,`descr` FROM ".$f->conf('pre')."categories";
All of those backquotes are executing external shell commands,
attempting to execute "cid", "name", "descr" etc. They fail to
find the command but it is still forking and executing the shell
for each one.
Just take all the backquotes out of your sql statement,
and it should work.
$sql="SELECT cid,name,descr FROM ".$f->conf('pre')."categories";