In first Samuel 21, the Philistine princes warned King Achish about him. David, feigning madness, went from them. Certainly in the time period between I Samuel 21 and I Samuel 27, more was known about Saul chasing after David and that there was no place for him to seek refuge. King Achish of the Philistines offered him refuge and gave him Ziklag to settle in. It was located near area of Judah, where his own people lived. King Achish saw David for who he was and knew he could be trusted.
Philistia was a pagan land and did not worship the God of David. It must have been difficult for him just as it is for us in today's environment. David was wise and made the best of what was allotted to him. God provided for him in just the right way. The book of Philippians (no connection to Philistia) comes immediately to my mind in this regard. The major theme in Philippians is confidence (Philippians 4:13), completeness (Philippians 4:19) and contentment (Philippians 4:11). Knowing what God offers us first makes us extremely powerful to walk wisely among people who don't believe the same things we do.
12 Wherefore, my beloved, as ye have always obeyed, not as in my presence only, but now much more in my absence, work out your own salvation with fear and trembling.13 For it is God which worketh in you both to will and to do of his good pleasure.14 Do all things without murmurings and disputings:15 That ye may be blameless and harmless, the sons of God, without rebuke, in the midst of a crooked and perverse nation, among whom ye shine as lights in the world;The words: 'fear and trembling' convey the message of respect and trust in God, realizing that we need God to the extent we do our best to fulfill what God asks of us. We are completely equipped to do what God sets before us. Read up on confidence, completeness and contentment in Philippians. The Book of Colossians continues along the same vein emphasizing how complete we really are despite what is going on around us.