|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Database Access (MySQL)
|
|
|
62b044 |
*
|
|
|
62b044 |
* Provides default database access values, and functions used to
|
|
|
62b044 |
* access data in both newbb and phpBB.
|
|
|
62b044 |
*
|
|
|
62b044 |
* --
|
|
|
62b044 |
* Alain Reguera Delgado <alain.reguera@gmail.com>
|
|
|
62b044 |
***/
|
|
|
62b044 |
|
|
|
62b044 |
class DB_MYSQL
|
|
|
62b044 |
{
|
|
|
62b044 |
public $db_conn;
|
|
|
62b044 |
|
|
|
62b044 |
public $db_host;
|
|
|
62b044 |
public $db_user;
|
|
|
62b044 |
public $db_pass;
|
|
|
62b044 |
public $db_xoops_db;
|
|
|
62b044 |
public $db_xoops_tbl;
|
|
|
62b044 |
public $db_phpbb_db;
|
|
|
62b044 |
public $db_phpbb_tbl;
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Class Construct
|
|
|
62b044 |
***/
|
|
|
62b044 |
|
|
|
62b044 |
function __construct()
|
|
|
62b044 |
{
|
|
|
62b044 |
// Initialize configuration values
|
|
|
62b044 |
$this->db_host = 'localhost';
|
|
|
62b044 |
$this->db_user = 'root';
|
|
|
62b044 |
$this->db_pass = '';
|
|
|
62b044 |
$this->db_xoops_db = 'xoops';
|
|
|
62b044 |
$this->db_xoops_tbl = 'xoops_';
|
|
|
62b044 |
$this->db_phpbb_db = 'phpBB';
|
|
|
62b044 |
$this->db_phpbb_tbl = 'phpbb_';
|
|
|
62b044 |
|
|
|
62b044 |
// Reinitialize configuration values
|
|
|
62b044 |
$config = array('db_host', 'db_user', 'db_pass', 'db_xoops_db',
|
|
|
62b044 |
'db_xoops_tbl', 'db_phpbb_db', 'db_phpbb_tbl');
|
|
|
62b044 |
|
|
|
62b044 |
foreach ( $config as $param )
|
|
|
62b044 |
{
|
|
|
62b044 |
if ( ! isset( $_SESSION[$param] ) )
|
|
|
62b044 |
{
|
|
|
62b044 |
$_SESSION[$param] = $this->$param;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
$_SESSION[$param] = isset($_POST[$param])?$_POST[$param]:$_SESSION[$param];
|
|
|
62b044 |
|
|
|
62b044 |
$this->$param = $_SESSION[$param];
|
|
|
62b044 |
}
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Connect
|
|
|
62b044 |
*/
|
|
|
62b044 |
function connect()
|
|
|
62b044 |
{
|
|
|
62b044 |
// Connect to MySQL database
|
|
|
62b044 |
$this->db_conn = mysql_connect( $this->db_host,
|
|
|
62b044 |
$this->db_user,
|
|
|
62b044 |
$this->db_pass );
|
|
|
62b044 |
if ( $this->db_conn )
|
|
|
62b044 |
{
|
|
|
62b044 |
return true;
|
|
|
62b044 |
}
|
|
|
62b044 |
else
|
|
|
62b044 |
{
|
|
|
62b044 |
return false;
|
|
|
62b044 |
}
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* DB Configuration
|
|
|
62b044 |
*/
|
|
|
62b044 |
function get_configForm( $disabled = '' )
|
|
|
62b044 |
{
|
|
|
62b044 |
$htmlblock = array();
|
|
|
62b044 |
|
|
|
62b044 |
array_push( $htmlblock,
|
|
|
62b044 |
// Common DB Configuration
|
|
|
62b044 |
'Common DB configuration:',
|
|
|
62b044 |
'',
|
|
|
62b044 |
'Server: ',
|
|
|
62b044 |
'<input type="text" name="db_host" value="'.$this->db_host.'" '.$disabled.' />',
|
|
|
62b044 |
|
|
|
62b044 |
'Username:',
|
|
|
62b044 |
'<input type="text" name="db_user" value="'.$this->db_user.'" '.$disabled.' />',
|
|
|
62b044 |
|
|
|
62b044 |
'Password:',
|
|
|
62b044 |
'<input type="password" name="db_pass" value="'.$this->db_pass.'" '.$disabled.' />',
|
|
|
62b044 |
'',
|
|
|
62b044 |
|
|
|
62b044 |
// Xoops Configuration
|
|
|
62b044 |
'Xoops configuration:',
|
|
|
62b044 |
'',
|
|
|
62b044 |
'Xoops database name:',
|
|
|
62b044 |
'<input type="text" name="db_xoops_db" value="'.$this->db_xoops_db.'" '.$disabled.' />',
|
|
|
62b044 |
|
|
|
62b044 |
'Xoops table prefix:',
|
|
|
62b044 |
'<input type="text" name="db_xoops_tbl" value="'.$this->db_xoops_tbl.'" '.$disabled.' />',
|
|
|
62b044 |
|
|
|
62b044 |
'',
|
|
|
62b044 |
|
|
|
62b044 |
// phpBB Configuration
|
|
|
62b044 |
'phpBB configuration:',
|
|
|
62b044 |
'',
|
|
|
62b044 |
'Phpbb database name:',
|
|
|
62b044 |
'<input type="text" name="db_phpbb_db" value="'.$this->db_phpbb_db.'" '.$disabled.' />',
|
|
|
62b044 |
|
|
|
62b044 |
'Phpbb table prefix:',
|
|
|
62b044 |
'<input type="text" name="db_phpbb_tbl" value="'.$this->db_phpbb_tbl.'" '.$disabled.' />',
|
|
|
62b044 |
'');
|
|
|
62b044 |
|
|
|
62b044 |
return $htmlblock;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Query
|
|
|
62b044 |
*/
|
|
|
62b044 |
function query( $sql )
|
|
|
62b044 |
{
|
|
|
62b044 |
$this->connect();
|
|
|
62b044 |
$result = mysql_query( $sql, $this->db_conn );
|
|
|
62b044 |
if ( $result )
|
|
|
62b044 |
{
|
|
|
62b044 |
return $result;
|
|
|
62b044 |
}
|
|
|
62b044 |
else
|
|
|
62b044 |
{
|
|
|
62b044 |
return false;
|
|
|
62b044 |
}
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Check existance
|
|
|
62b044 |
*/
|
|
|
62b044 |
function check_existance( $name )
|
|
|
62b044 |
{
|
|
|
62b044 |
|
|
|
62b044 |
switch ( $name )
|
|
|
62b044 |
{
|
|
|
62b044 |
case 'phpbb':
|
|
|
62b044 |
$check_dbname = $this->db_phpbb_db;
|
|
|
62b044 |
$check_suffix = $this->db_phpbb_tbl;
|
|
|
62b044 |
$check_tables = array('users', 'forums', 'topics', 'posts');
|
|
|
62b044 |
break;
|
|
|
62b044 |
|
|
|
62b044 |
case 'xoops':
|
|
|
62b044 |
$check_dbname = $this->db_xoops_db;
|
|
|
62b044 |
$check_suffix = $this->db_xoops_tbl;
|
|
|
62b044 |
$check_tables = array('users', 'bb_forums', 'bb_topics', 'bb_posts', 'bb_posts_text');
|
|
|
62b044 |
break;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
$error = 0;
|
|
|
62b044 |
$table_list = array();
|
|
|
62b044 |
|
|
|
62b044 |
// Check database existance
|
|
|
62b044 |
if ( ! mysql_select_db( $check_dbname ) )
|
|
|
62b044 |
{
|
|
|
62b044 |
$error++;
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
// Check tables existance
|
|
|
62b044 |
else
|
|
|
62b044 |
{
|
|
|
62b044 |
$sql = 'SHOW TABLES FROM ' . $check_dbname . ';';
|
|
|
62b044 |
$result = $this->query( $sql );
|
|
|
62b044 |
while ( $row = mysql_fetch_row ($result) )
|
|
|
62b044 |
{
|
|
|
62b044 |
array_push($table_list, $row[0]);
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
foreach ($check_tables as $tablename)
|
|
|
62b044 |
{
|
|
|
62b044 |
$tablename = $check_suffix . $tablename;
|
|
|
62b044 |
if (in_array($tablename, $table_list) === false )
|
|
|
62b044 |
{
|
|
|
62b044 |
$error++;
|
|
|
62b044 |
}
|
|
|
62b044 |
}
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
if ( $error == 0 )
|
|
|
62b044 |
{
|
|
|
62b044 |
return true;
|
|
|
62b044 |
}
|
|
|
62b044 |
else
|
|
|
62b044 |
{
|
|
|
62b044 |
return false;
|
|
|
62b044 |
}
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
/***
|
|
|
62b044 |
* Class Destruct
|
|
|
62b044 |
***/
|
|
|
62b044 |
|
|
|
62b044 |
function disconnect()
|
|
|
62b044 |
{
|
|
|
62b044 |
mysql_close( $this->db_conn );
|
|
|
62b044 |
}
|
|
|
62b044 |
}
|
|
|
62b044 |
|
|
|
62b044 |
$db = new DB_MYSQL;
|
|
|
62b044 |
?>
|