Visto che la mia WHERE è composta da una serie di AND ho provato a simulare volutamente un errore scrivendo così (in rosso l'errore simulato)
WHERE $rez[1]=a AND '$a[campo']='1'
ed utilizzando la funzione mysql-error()
Il risultato è questo:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=a AND ''=1 ...
Sembra che non riesca a leggere una variabile in array contenente come indice un campo della tabella....
Il campo della tabella "CAMPO" è settato come uno SMALLINT e provando a mettere nella WHERE campo='1' (per esempio) funziona così come scrivendo '$a[1]'='1' funziona...