Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: One registration two MU?  (Read 2845 times)

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
One registration two MU?
« on: March 11, 2008, 05:21:00 pm »

Hi all
I have already MU installed for users, and I try to make a snewsMU forum!  ;D
This MU forum is going to be a separate snews so my question is how I can make one registration and users can use those two MU
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: One registration two MU?
« Reply #1 on: March 11, 2008, 07:31:05 pm »

We've been down this road before... just can't remember where the posts are ATM. Here's how I did it last year.

1. Start with single database that uses one set of user-related tables and two sets of settings and content-related tables:
   DATABASE TABLES:
   - used by the main installation
   articles
   categories   
   comments   
   settings
   - used by the forum installation
   forum_articles
   forum_categories
   forum_comments
   forum_settings
   - used by both installations
   users
   guests (if used)

2. Next we want to choose which tables the forum installation will use, individually, by name. We can already make this install access all tables with the forum_ prefix on their names in the database... by using forum_ in the $db variable value for prefix... but it would not find the users and guests tables because we aren't using a prefix on their names. So we create $variables for each of the table-names at the top of the engine file (or in the cong file if used)... and we use the table-names as the values. We then replace all table-names in all queries in every function with their respective variables. We can then use the values for different tables as we choose.
 
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: One registration two MU?
« Reply #2 on: March 12, 2008, 12:58:13 am »

OK is difficult for me.
But here is my idea how I thing must be..

Registration, database Registration-users [tables (users)]
snewsMU have database1 [tables (articles, categories, comments, settings)]

In snewsMU we create a new function db2 for users
and a new function connect_to_db2()

Now only have to change query(users), update, whatever, in snewsMU
Something like this
Quote
mysql_query("SHOW TABLES LIKE '%".db2('prefix')."users'")))

So if we have separate the database users then we can connect to another snewsMU like above.

You thing like this is possible?

Just a thought
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: One registration two MU?
« Reply #3 on: March 12, 2008, 03:24:31 am »

It sounds like it might work. I suppose the only way to find out would be to give it a try-run.
When you make a change to Query strings, make a copy of the string and comment it out before you change it... call it your default string... so you can re-use it again when you need it.  ;)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: One registration two MU?
« Reply #4 on: March 12, 2008, 03:57:31 pm »

Well i try it and i have some problems, the good news is site come up
the bad news is i can't login, register and don't show users, quests online
So here is how i try
Two databases like this
Quote
// DATABASE VARIABLES
function db($variable) {
   $db = array();
   $db['website'] = 'localhost';
   $db['dbhost'] = 'localhost'; //MySQL Host
   $db['dbname'] = 'db1-snewsmu'; //Database Name
   $db['dbuname'] = 'test'; //Database Username
   $db['dbpass'] = 'tpass'; //Database password
   $db['prefix'] = ''; //Database prefix
   $db['dberror'] = '<strong>There was an error while connecting to the database.</strong> <br /> Check your database settings.'; //Database error message
   return $db[$variable];
}

#User_s-Multi
function db2($variable) {
   $db2 = array();
   $db2['dbhost'] = 'localhost'; //MySQL Host
   $db2['dbname'] = 'regusers-mu'; //Database Name
   $db2['dbuname'] = 'test'; //Database Username
   $db2['dbpass'] = 'tpass; //Database password
   $db2['prefix'] = ''; //Database prefix
   $db2['dberror'] = '<strong>There was an error while connecting to the database.</strong> <br /> Check your database settings.'; //Database error message
   return $db2[$variable];
}

// CONNECT TO DATABASE
Quote
function connect_to_db() {
   $db = mysql_connect(db('dbhost'), db('dbuname'), db('dbpass'), true);
   mysql_select_db(db('dbname')) or die(db('dberror'));
}
#User_s-Multi
function connect_to_db2() {
   $db = mysql_connect(db2('dbhost'), db2('dbuname'), db2('dbpass'), true);
   mysql_select_db(db2('dbname')) or die(db2('dberror'));
}

// STARTUP
Quote
function snews_startup() {
   connect_to_db();
   #User_s-Multi
   connect_to_db2();
....

All query, mysql_num_rows, mysql_query, with users i have change it to db2('prefix')
15 changes

The problem (I thing) is to function retrieve, function retrieve_array
i try it like this
Quote
function retrieve($column, $table, $field, $value) {
   $query = "SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'";
   $query = "SELECT $column FROM ".db2('prefix')."$table WHERE $field = '$value'";
...
the same to function retrieve_array
Any idea?

I am to lousy when comes to php sql, so don't expect a lot  ;D
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: One registration two MU?
« Reply #5 on: March 12, 2008, 04:35:18 pm »

Quote from: sibas
1 - I am to lousy when comes to php sql, so don't expect a lot   ;D
2 - The good news is site comes up.
3 - The bad news is I can't login, register and don't show users, quests online.

1 - Me too.  :P
2 - Good - you mean the second site you want to use for the forum?
3 - How about the main site- can you login and stuff in it?

I don't know for sure if your approach will work as intended. But it is good that you are trying to make it work... would never know otherwise.
What about the other tables for the second site - articles, categories, comments & settings - are you using another set of tables in another dbase... or are they in db2?
Perhaps we cannot connect to 2 databases in the same engine file. No one has done this before and made it work... and maybe that's why we did it with all tables in one database when we tried running 2 sites in the same domain last year.

All you can do is keep on trying. Even if you get discouraged and decide to stop working on this method... it's a good idea to keep this project installed and keep track of what you do in files in a "Project Notes" folder for future reference. You can always work on it later if something does come up.

Perhaps Bakercad or Joost or Equilni might have some comments on whether this method would work or not.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: One registration two MU?
« Reply #6 on: March 12, 2008, 07:03:56 pm »

There no other site (forum) for now
I try to connect 1 snewsMU with different databases
There are 2 db's
db1-snewsmu have [tables (articles, categories, comments, settings)]
and regusers-mu have [tables (users)]

What is the relation with function s($variable) and function retrieve?
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: One registration two MU?
« Reply #7 on: March 12, 2008, 07:31:42 pm »

What is the relation with function s($variable) and function retrieve?


function s($variable)
This function queries the settings table in the database using SELECT to get all of the values stored in that table so they can be available for the functions that use those variables. If they are not available, then the site don't work so good.

function retrieve
Here is a copy of the 2 functions from Mika's snews16Dev.php file... the one he put all his development notes into. His comments are noted in these functions and say what they do pretty well already... so there is no point in me re-writing what he says here:  ;D

Code: [Select]
<?php

// SMART RETRIEVE FUNCTION
function retrieve($column$table$field$value) {
/*
- if you need a single result from some table based on a single where-clause,
you could use this small routine which will save you from excessive code repetition
- in short, it's meaning would be: fetch a single result ($retrieve) from your table ($table)
based on a condition found in column ($column) where it's field ($field) must be equal to some value ($value)
- I've been thinking... is it smart after all? The explanation is longer than the actual code?!
*/
$query "SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'";
$result mysql_query($query);
while ($r mysql_fetch_array($result)) {$retrieve $r[$column];}
return $retrieve;
}

// FIND CATEGORY'S SEF TITLE THROUGH ARTICLE'S CATEGORY ID
function find_cat_sef($categoryid) {    # Ref#054
/*
- this is a newer variation of retrieve() function inherited from previous sNews CMS version,
and it does the same thing: it's result is category seftitle found with category id
- older MySQL query has been replaced with retrieve() function
- small addition is category check; if no category is found, then category = "home"
*/
$SEF retrieve('seftitle','categories','id',$categoryid);
$cat_sef_title = isset($SEF) ? $SEF l('home_sef');
return $cat_sef_title;
}

?>

Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU