For my situation, using MAMP for my Magento project running locally in OSX I receive this error when the wrong PHP version is being used because my .bash_profile is not being properly sourced or needs to be sourced again...
Make sure the php version and file you are suggesting to use are whats being used by the system by running:
$ which php
<---- in my case the php i am wanting to use is in the MAMP directory, so /user/bin/php is incorrect.
Once i source my bash_profile i am using the correct php and the error goes away.
Your bash_profile allows you to set a specific path for the php/mysql versions you are wanting to use, you could have a separate profile for each project if required:
/// below is an example of what you would use in your bash_profile in my case
In order to use this bash profile you must 'source' the file.
Then when you check the php version it should return the correct path
Hope this helps someone.