That should work - in my quest to learn PHP I’ve just moved my database connection code to a separate file and used require_once() to include it, then added a function definition in that same file, without trouble.
What I did find, that I wasn’t expecting, is that even if you put the include/require code inside a pair of <?php and ?> tags, you must still have those tags within your included file, otherwise the contents just get displayed. Could that be the problem you’re having? If not, post the full included fle, and the errors that you’re receiving as ‘throws all errors’ kind of makes it hard to diagnose.
function bindStatements() {
$stmt->bindColumn('name','$name');
$stmt->bindColumn('address','$address');
$stmt->bindColumn('country','$country');
}
There are several problems with this approach. First, you don’t have access to variables outside of the function, you have to pass in the data you want to use as parameters. But, even if we passed in $stmt as an argument, bindColumn wouldn’t work here as you’re calling it within the scope of the function and the variables you bind won’t be available to the code outside. You’d get ‘undefined variable name’ errors from your print statement.