I have a php file in which I connect to the database. At the end of the file I require another file in which I also have a connection. This causes the error:
"Fatal error: Cannot redeclare getConnection() (previously declared in..."
It's important for me to use two separate files, so I would like to know how to close the connection before opening a new one (in the file fetched via require).
I thought that closeCursor() would make it work, but unfortunately it doesn't happen. How can I solve this problem?
require('../misc/database.php');
$db = getConnection();
$to = 'bla@gmail.com';
$from = 'bla@gmail.com';
$fromName = 'JaSama';
$subject = 'Informacja o nowym użytkowniku';
$body = 'Zarejestrował się nowy użytkownik. Edytuj ilość mieszkańców w miastach.';
$altBody = 'Zarejestrował się nowy użytkownik. Edytuj ilość mieszkańców w miastach.';
$created = date('Y-m-d H:i:s');
$statement = $db->prepare("INSERT INTO `mailqueue`(`to`, `from`, `fromName`, `subject`, `body`, `altBody`, `created`) VALUES (:to, :from, :fromName, :subject, :body, :altBody, :created)");
$statement->bindValue(':to', $to);
$statement->bindValue(':from', $from);
$statement->bindValue(':fromName', $fromName);
$statement->bindValue(':subject', $subject);
$statement->bindValue(':body', $body);
$statement->bindValue(':altBody', $altBody, PDO::PARAM_STR);
$statement->bindValue(':created', $created);
$statement->execute();
$statement->closeCursor();
require 'mailToDatabaseHandlowiec.php';