codice:
	function holes($tablename, $idname)
	{
		$query = "select max($idname) from $tablename";
		$res = mysql_query($query);
		list($max_id) = mysql_fetch_row($res);
		$query = "select count(*) from $tablename";
		$res = mysql_query($query);
		list($count_id) = mysql_fetch_row($res);
		$count_id = $db->get($query);
		if($max_id == $count_id)
		{
			return $max_id++;
		}
		else
		{
			$i = 1;
			$not_id = array();
			$trovato = 0;
			while($i<$count_id and !$trovato)
			{
				$query = "select $idname from $tablename where find_in_set($i, id) >0;";
				$res = mysql_query($query);
				list($id_find) = mysql_fetch_row($res);
				if($id_find)
					$i++;
				else
					$trovato = 1;
			}
			return $i;
		}
	}

	echo holes('articoli', 'id');
Questa funzione è l'unica idea che mi è venuta. Non mi sono studiato nel manuale se si può fare qualcosa di simile attraverso una semplice query. Qualcuno più esperto di mysql potrebbe darti un maggiore aiuto.