I have created an import file to import my old forum from the phpbb3 system. That database is on the same server.
I created this file and saved it at /sys/CODOF/Importer/Drivers/
file named phpbb3.php:
corrected code:
<?php
/*
* @CODOLICENSE
*/
namespace CODOF\Importer\Drivers;
/**
*
* SMF uses concept of boards .
* They have boards -> categories -> topics -> posts
*
* But codoforum has categories -> topics -> posts
*
* We have seen from the tables that all topics and posts of SMF are linked
* with their boards .
*
* So, we will treat boards of SMF as categories of codoforum . We will not
* concern ourselves with categories of SMF .
*
*/
class phpbb3 {
public $max_rows = 100;
/**
* Mention whether your posts table contain topic message as a post or not ?
*
* If it is set to true , make sure the query in get_posts() below returns
* messages of all topics too
*
* Note: Importer runs faster when posts table has the message of topics
* but sadly not all forum systems are the same :(
* @var type
*/
public $post_has_topic = true;
private $db;
public function __construct($db) {
$this->db = $db;
}
/**
* Table prefix
* @var type
*/
public function set_prefix($prefix) {
define('DBPRE', $prefix);
}
/**
*
* Selects
* category id -> cat_id
* category name -> cat_name
* category description -> cat_description
* category order -> cat_order
* category parent id -> cat_pid
* @return type
*/
public function get_cats() {
$qry = "SELECT b.forum_id AS cat_id, b.forum_name AS cat_name, b.forum_desc AS cat_description,
b.left_id AS cat_order, b.parent_id AS cat_pid
FROM ".DBPRE."forums AS b WHERE b.forum_type=1";
$res = $this->db->query($qry);
return $res->fetchAll();
}
/**
*
* Selects
* topic id -> topic_id
* topic title -> title
* category id -> cat_id
* topic created time -> topic_created
* topic updated time -> topic_updated
* last post id -> last_post_id [optional]
* last post uid -> last_post_uid [optional]
* last post name -> last_post_name [optional]
* last post time -> last_post_time [optional]
* user id who creaed -> uid
* post message -> message [Must be selected when $post_has_topic=false Otherwise OPTIONAL]
* post id -> post_id [Must be selected when $post_has_topic=true Otherwise OPTIONAL]
* @param type $start
* @return type
*/
public function get_topics($start) {
$qry = "SELECT t.topic_id AS topic_id, t.topic_title AS title,t.forum_id AS cat_id,t.topic_time AS topic_created,
t.topic_last_post_time AS topic_updated, t.topic_poster AS uid, t.topic_first_post_id AS post_id,
p.post_text AS message
FROM ".DBPRE."topics AS t
INNER JOIN ".DBPRE."posts AS p ON p.topic_id=t.topic_first_post_id
LIMIT $this->max_rows OFFSET $start";
$res = $this->db->query($qry);
$result = $res->fetchAll(\PDO::FETCH_ASSOC);
return $result;
}
/**
*
* Selects
* category id -> cat_id
* topic id -> topic_id
* post id -> post_id
* user id -> uid
* post message -> message
* post created time -> post_created
* post modified time -> post_modified
* @param type $start
* @return type
*/
public function get_posts($start) {
$qry = "SELECT t.forum_id AS cat_id, p.topic_id AS topic_id, p.poster_id AS uid,
p.post_id AS post_id,p.post_text AS message, p.post_time AS post_created,
p.post_time AS post_modified
FROM ".DBPRE."posts AS p
INNER JOIN ".DBPRE."topics as t ON t.topic_id=p.topic_id
LIMIT $this->max_rows OFFSET $start";
$res = $this->db->query($qry);
$result = $res->fetchAll(\PDO::FETCH_ASSOC);
return $result;
}
/**
* Selects
* user id -> uid
* username -> username
* nickname -> name
* password -> pass
* email -> mail
* forum signature -> signature
* user created time -> created
* user last login time -> last_access
* user status -> status
* user avatar url -> avatar
* user role id -> rid [OPTIONAL]
* @param type $start
* @return type
*/
public function get_users($start) {
$qry = "SELECT u.user_id AS id, u.username AS username, u.username AS name, u.user_password AS pass,
u.user_email AS mail, u.user_sig AS signature, u.user_regdate AS created,
u.user_lastvisit AS last_access,
CASE WHEN u.user_rank='yes' THEN 0 ELSE 1 END AS user_status,
u.user_avatar AS avatar
FROM ".DBPRE."users AS u
LIMIT $this->max_rows OFFSET $start";
$res = $this->db->query($qry);
$result = $res->fetchAll(\PDO::FETCH_ASSOC);
//var_dump($result);
return $result;
}
/**
* Get the userid by email
* This is used pre-import to check if admin account email address
* given is correct or not
*
* @param type $mail
*/
public function get_user_by_mail($mail) {
$qry = "SELECT user_id AS uid FROM ".DBPRE."users WHERE user_email=? ";
$obj = $this->db->prepare($qry);
$obj->execute(array($mail));
$res = $obj->fetch();
if (!empty($res)) {
return $res['uid'];
}
return false;
}
}
When I run it on my server at System/Importer I can select phpbb3. My error message is:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydomain.phpbb3_USERS' doesn't exist' in ...
I edited all fields to correspond the fields for phpbb3 and table phpbb3_USERS does exist.
By the way, my old demo categories from the installation of Codoforum are gone now so that went well.
What am I missing here?
I have created an import file to import my old forum from the phpbb3 system. That database is on the same server.
I created this file and saved it at /sys/CODOF/Importer/Drivers/
file named phpbb3.php:
_corrected code:_
````
&lt;?php
/*
* @CODOLICENSE
*/
namespace CODOF\Importer\Drivers;
/**
*
* SMF uses concept of boards .
* They have boards -&gt; categories -&gt; topics -&gt; posts
*
* But codoforum has categories -&gt; topics -&gt; posts
*
* We have seen from the tables that all topics and posts of SMF are linked
* with their boards .
*
* So, we will treat boards of SMF as categories of codoforum . We will not
* concern ourselves with categories of SMF .
*
*/
class phpbb3 {
public $max_rows = 100;
/**
* Mention whether your posts table contain topic message as a post or not ?
*
* If it is set to true , make sure the query in get_posts() below returns
* messages of all topics too
*
* Note: Importer runs faster when posts table has the message of topics
* but sadly not all forum systems are the same :(
* @var type
*/
public $post_has_topic = true;
private $db;
public function __construct($db) {
$this-&gt;db = $db;
}
/**
* Table prefix
* @var type
*/
public function set_prefix($prefix) {
define('DBPRE', $prefix);
}
/**
*
* Selects
* category id -&gt; cat_id
* category name -&gt; cat_name
* category description -&gt; cat_description
* category order -&gt; cat_order
* category parent id -&gt; cat_pid
* @return type
*/
public function get_cats() {
$qry = "SELECT b.forum_id AS cat_id, b.forum_name AS cat_name, b.forum_desc AS cat_description,
b.left_id AS cat_order, b.parent_id AS cat_pid
FROM ".DBPRE."forums AS b WHERE b.forum_type=1";
$res = $this-&gt;db-&gt;query($qry);
return $res-&gt;fetchAll();
}
/**
*
* Selects
* topic id -&gt; topic_id
* topic title -&gt; title
* category id -&gt; cat_id
* topic created time -&gt; topic_created
* topic updated time -&gt; topic_updated
* last post id -&gt; last_post_id [optional]
* last post uid -&gt; last_post_uid [optional]
* last post name -&gt; last_post_name [optional]
* last post time -&gt; last_post_time [optional]
* user id who creaed -&gt; uid
* post message -&gt; message [Must be selected when $post_has_topic=false Otherwise OPTIONAL]
* post id -&gt; post_id [Must be selected when $post_has_topic=true Otherwise OPTIONAL]
* @param type $start
* @return type
*/
public function get_topics($start) {
$qry = "SELECT t.topic_id AS topic_id, t.topic_title AS title,t.forum_id AS cat_id,t.topic_time AS topic_created,
t.topic_last_post_time AS topic_updated, t.topic_poster AS uid, t.topic_first_post_id AS post_id,
p.post_text AS message
FROM ".DBPRE."topics AS t
INNER JOIN ".DBPRE."posts AS p ON p.topic_id=t.topic_first_post_id
LIMIT $this-&gt;max_rows OFFSET $start";
$res = $this-&gt;db-&gt;query($qry);
$result = $res-&gt;fetchAll(\PDO::FETCH_ASSOC);
return $result;
}
/**
*
* Selects
* category id -&gt; cat_id
* topic id -&gt; topic_id
* post id -&gt; post_id
* user id -&gt; uid
* post message -&gt; message
* post created time -&gt; post_created
* post modified time -&gt; post_modified
* @param type $start
* @return type
*/
public function get_posts($start) {
$qry = "SELECT t.forum_id AS cat_id, p.topic_id AS topic_id, p.poster_id AS uid,
p.post_id AS post_id,p.post_text AS message, p.post_time AS post_created,
p.post_time AS post_modified
FROM ".DBPRE."posts AS p
INNER JOIN ".DBPRE."topics as t ON t.topic_id=p.topic_id
LIMIT $this-&gt;max_rows OFFSET $start";
$res = $this-&gt;db-&gt;query($qry);
$result = $res-&gt;fetchAll(\PDO::FETCH_ASSOC);
return $result;
}
/**
* Selects
* user id -&gt; uid
* username -&gt; username
* nickname -&gt; name
* password -&gt; pass
* email -&gt; mail
* forum signature -&gt; signature
* user created time -&gt; created
* user last login time -&gt; last_access
* user status -&gt; status
* user avatar url -&gt; avatar
* user role id -&gt; rid [OPTIONAL]
* @param type $start
* @return type
*/
public function get_users($start) {
$qry = "SELECT u.user_id AS id, u.username AS username, u.username AS name, u.user_password AS pass,
u.user_email AS mail, u.user_sig AS signature, u.user_regdate AS created,
u.user_lastvisit AS last_access,
CASE WHEN u.user_rank='yes' THEN 0 ELSE 1 END AS user_status,
u.user_avatar AS avatar
FROM ".DBPRE."users AS u
LIMIT $this-&gt;max_rows OFFSET $start";
$res = $this-&gt;db-&gt;query($qry);
$result = $res-&gt;fetchAll(\PDO::FETCH_ASSOC);
//var_dump($result);
return $result;
}
/**
* Get the userid by email
* This is used pre-import to check if admin account email address
* given is correct or not
*
* @param type $mail
*/
public function get_user_by_mail($mail) {
$qry = "SELECT user_id AS uid FROM ".DBPRE."users WHERE user_email=? ";
$obj = $this-&gt;db-&gt;prepare($qry);
$obj-&gt;execute(array($mail));
$res = $obj-&gt;fetch();
if (!empty($res)) {
return $res['uid'];
}
return false;
}
}
````
When I run it on my server at System/Importer I can select phpbb3. My error message is:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydomain.phpbb3_USERS' doesn't exist' in ...
I edited all fields to correspond the fields for phpbb3 and table phpbb3_USERS does exist.
By the way, my old demo categories from the installation of Codoforum are gone now so that went well.
What am I missing here?
edited Jan 5 '15 at 5:41 pm