I'm writing a single PHP script to migrate topics from an old forums site to a new one.
- The old forums site use database "old_forums"
- Thew new forums site use database "new_forums"
- MySQL user "forums" has all privileges to both databases (I'm using 1 single user for convenience but I would not have any problems using 2 different users if required)
I have both forum hosted on the the same host - localhost
The script I have the following structure
<?php
class Forum {
//constants
const HOST = "localhost";
const DB_USER = "forums";
const DB_PASS = "forums";
...
//properties e.g. topic title, topic content
}
class OldForum extends Forum {
const DB_NAME_OLD = "old_forums";
public static function exportTopics() {
//some code
}
}
class NewForum extends Forum {
const DB_NAME_NEW = "new_forums";
public static function importTopics() {
//some code
}
}
OldForum::exportTopics();
NewForum::importTopics();
?>
I understand that I'm mixing procedural & object-oriented programming PHP (OOPP) here. I'm new to object-oriented PHP but (I have experience with Java so I'm very open to some guide to make this pure OOPP)
I would like to ultilise 1 single MySQL connection for both OldForum and NewForum class.
Where should I instantiate a mysqli object?
e.g. inside Forum class' constructor or have a new mysqli object as a property of class Forum
so that I would create a new Forum object to initiate a MySQL connection
$a_forum = new Forum();