Thoughts on organizing code for multiple mysql queries in php scripts
You're on the right track, what you're looking for is a DAL (Data Abstraction Layer), a class that represents a database connection.
This will allow you to move your common code into the class so you can simply construct your SQL statement and pass it in, with the method returning the expected data.

At a minimum you'd typically have, but aren't limited to:


Constructor (__construct) to create a new database connection using the relevant permissions.
Method to run your select statement (after input sanitization), returning a result set.
Method to run statements that don't return a result set.
Destructor (__destruct) to clean up and free any resources.


This would give you the following advantages:


Code reuse: only 1 copy of logging, connection initialization code, in 1 place.
Code encapsulation: The details are hidden behind a public interface so you can easily fix bugs and add new features without breaking existing SQL calls.
Pass in a complete SQL statement for centralized execution of SQL code.
Optionally pass in a parameter to specify calling Fetch/FetchAll/FetchColumn.
Easier debugging since your class will very quickly become very reliable as it gets heavily used and bugs are noticed and fixed.
Logging would be done automatically whenever you ran an SQL statement.
Easily add additional methods, such as input validation/sanitization.
Additional methods for specific purposes depending on your requirements.