Hello everyone,
I have a very basic question, as I’m very new working with Kirby. Here an example:
mysnippet.php contains database connections for multiple MySql-Databases I use e.g.:
$type = option('MyDB.type');
$server = option('MyDB.host');
$dbName = option('MyDB.database');
$user = option('MyDB.user');
$psw = option('MyDB.password');
$port = option('MyDB.port');
try{
$conn = new PDO("mysql:host=$server; dbname=$dbName", $user, $psw);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}catch(PDOException $e){
echo $e->getMessage();
}
snippet ('mysnippet');
Error thrown with message “Call to a member function query() on null” at this row in the template.
Template:
$result = $conn->query($sql,[$bind]);
include ('site/snippets/mysnippet.php');
Using include works fine.
What exactly is the difference between snippet and include?
Thanks a lot, in advance
Best Regards