The point of having a database class/wrapper is that it contains all the lower-level database logic and your application (main code) only forms the queries and validates/supplies the data being put into the queries and calls the database class methods to actually perform the database operations.
The error message is pretty self explanatory though, your db class doesn't have a ->prepare() method.
You db class does have a ->query() method, but it is foo-bar. You should not be making a database connection every time you run a query. You should be making a database connection once when you create an instance of the db class.
Get your existing db class organized and working with a normal (non-prepared) query, then add a prepared query method to it with the logic necessary to prepare, dynamically bind any input data, run the query, check for errors, dynamically bind any result,
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.