Generally the gas metallicity in distant galaxies can only be inferred by using a few prominent emission lines . Various theoretical models have been used to predict the relationship between emission line fluxes and metallicity , suggesting that some line ratios can be used as diagnostics of the gas metallicity in galaxies . However , accurate empirical calibrations of these emission line flux ratios from real galaxy spectra spanning a wide metallicity range are still lacking . In this paper we provide such empirical calibrations by using the combination of two sets of spectroscopic data : one consisting of low-metallicity galaxies with a measurement of [ O iii ] \lambda 4363 taken from the literature , including spectra from the Sloan Digital Sky Survey ( SDSS ) , and the other one consisting of galaxies in the SDSS database whose gas metallicity has been determined from various strong emission lines in their spectra . This combined data set constitutes the largest sample of galaxies with information on the gas metallicity available so far and spanning the widest metallicity range . By using these data we obtain accurate empirical relations between gas metallicity and several emission line diagnostics , including the R _ { 23 } parameter , the [ N ii ] \lambda 6584/H \alpha and [ O iii ] \lambda 5007/ [ N ii ] \lambda 6584 ratios . Our empirical diagrams show that the line ratio [ O iii ] \lambda 5007/ [ O ii ] \lambda 3727 is a useful tool to break the degeneracy in the R _ { 23 } parameter when no information on the [ N ii ] \lambda 6584 line is available . The line ratio [ Ne iii ] \lambda 3869/ [ O ii ] \lambda 3727 also results to be a useful metallicity indicator for high- z galaxies , especially when the R _ { 23 } parameter or other diagnostics involving [ O iii ] \lambda 5007 or [ N ii ] \lambda 6584 are not available . Additional , useful diagnostics newly proposed in this paper are the line ratios of ( H \alpha + [ N ii ] \lambda \lambda 6548,6584 ) / [ S ii ] \lambda 6720 , [ O iii ] \lambda 5007/H \beta , and [ O ii ] \lambda 3727/H \beta . Finally , we compare these empirical relations with photoionization models . We find that the empirical R _ { 23 } -metallicity sequence is strongly discrepant with respect to the trend expected by models with constant ionization parameter . Such a discrepancy is also found for other line ratios . These discrepancies provide evidence for a strong metallicity dependence of the average ionization parameter in galaxies . In particular , we find that the average ionization parameter in galaxies increases by \sim 0.7 dex as the metallicity decreases from 2 Z _ { \odot } to 0.05 Z _ { \odot } , with a small dispersion . This result should warn about the use of theoretical models with constant ionization parameter to infer metallicities from observed line ratios .