The Lord is near to the brokenhearted
And saves those who are contrite in spirit.
— Psalm 34:18
To be contrite means to be deeply sorrowful and repentant. I believe David had a realization of how proud and self-sufficient he had been during the period of his manifestation. He once was a powerful man enjoying success, but now he realized that God was his only means of survival.
Therefore, he could say that the Lord was near to everyone who has a broken heart and saves such as have a spirit of deep repentance. David had so much to repent of, but he did not have time for regret. He was of a contrite spirit, and that was enough.
Adapted from David: After God’s Heart, pages 66-67.