Assuming you’ve tried other cables and do t have another iPhone to try it with, you could have a look at the phone connector - quite often, over time, lint/dust builds up which still allows charging but not data. Pick it out with something not metallic like a toothpick. (Very common for people...