Results 1 to 10 of 18

Hybrid View

  1. #1
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: One database for two websites

    ... err guys. It can be done, and it doesn't require oodles of re-writing of core.

    For example:

    1. Create two sites in the same database with different database prefixes, e.g. "zen1_" and "zen2_".

    2. In the site pointing to "zen2_", edit the includes/database_tables.php file to change the following line
    define('TABLE_PRODUCTS', DB_PREFIX . 'products');
    to
    define('TABLE_PRODUCTS', 'zen1_products');
    This points the products table from site 2 to the products table for site 1.

    3. IMPORTANT now do step 2 for all the other product and category-related pages (you could separate them out, but you would really have to know what you're doing).

    Things to look out for (gotchas) ...

    If you're using mods that introduce different product types or new tables that extend any of the existing product or category tables then you'll need also to update the declarations for those tables which should be in the includes/extra_datafiles folders in the catalog and admin, though sometimes get embedded at the top of the mods main file.

    If you're using mods that hard-code the table names (naughty), then you will need to correct this in order for this approach to work.

    Be aware that if this doesn't work on your site, it's going to be difficult for us to provide support, since the problem will almost certainly be specific to non-core code being used on your site, that we can't see. However, conversely, we're making very limited changes to a single file, so it would be very easy to reverse.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  2. #2
    Join Date
    Mar 2010
    Posts
    4
    Plugin Contributions
    0

    Default Re: One database for two websites

    Thanks for the replies... I'll be looking in to that changing of the defines...

    Although I still feel the most for using views... I can't see how the restrictions on views would affect the shop behaviour:
    * It is not possible to create an index on a view.
    * Indexes can be used for views processed using the merge algorithm. However, a view that is processed with the temptable algorithm is unable to take advantage of indexes on its underlying tables (although indexes can be used during generation of the temporary tables).

    Subqueries cannot be used in the FROM clause of a view.
    If the view thing works, no lines of code, even no defines, have to be changed...

  3. #3
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: One database for two websites

    If I understand correctly what you're proposing, it would make the store that was relying on views unbelievably slow.

    Zen Cart frequently joins lots of tables together and the fields used to construct those joins have been carefully indexed to optimise response times.

    To perform those joins on unindexed views would create an enormous performance hit.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  4. #4
    Join Date
    Mar 2010
    Posts
    4
    Plugin Contributions
    0

    Default Re: One database for two websites

    Well, using the define option might work better then... maybe I'll try both, to see if there's any performance difference... but both solutions use the same approach... 'redirect' the data from one table to another.. :-)

  5. #5
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: One database for two websites

    Quote Originally Posted by RobotStore View Post
    Well, using the define option might work better then... maybe I'll try both, to see if there's any performance difference... but both solutions use the same approach... 'redirect' the data from one table to another.. :-)
    Hmmm. They're not really the same at all. A view isn't a table. It's really the output of a saved query. So the view approach crudely equates to replacing each table in product-related Zen Cart query, with a subquery that needs to be linked by full text comparisons in the absence of any indexing - hence the performance hit.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  6. #6
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: One database for two websites

    Quote Originally Posted by RobotStore View Post
    Well, using the define option might work better then... maybe I'll try both, to see if there's any performance difference... but both solutions use the same approach... 'redirect' the data from one table to another.. :-)
    They're not really the same.

    Plus, in v1.x there is an architectural limitation which requires that you have write privileges ("UPDATE") to the table so stats can be updated every time a visitor visits a product's info page. If you're using a read-only view then you'll encounter SQL errors.
    Instead, if you use the prefix approach suggested by kuroi you won't run into that problem.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: One database for two websites

    @frank18

    Schoolboy's approach would work fine, but there are some issues specific to how web hosts configure their hosting accounts that would need to be taken account off too.

    For many hosting accounts, database access is treated as integral to the account. It doesn't have to be, but it's understandably convenient for the hosts to manage it thus. Unfortunately, many hosts can only allow you one dedicated IP address per account, and therefore only one dedicated SSL. So even if you have many sites running off one database, you may have to make provision for them to use the same SSL cert when they go live.

    You also end up with two sets of code to patch and upgrade. Personally I prefer to run with one set of code and one database. There's the multisite mod for doing this, which is one approach. I use a different one.

    The hidden wholesale mod was originally conceived off as a way of running wholesale and retail sites from a single installation. However, my version of it centralised the condition for deciding which products could be used for which site, which makes it incredibly flexible. For example I have a client with a couple of extra fields on the product table to indicate to which site each product belongs (or both). I have another with a dedicated sale site that filters on whether a product has a sale price.

    In these cases there is also a tweak to config files to ensure that incoming URL is perpertuated, and an overridden init_templates file to ensure that the right template is used for each variant of the site.

    Hope that provides extra food for thought and not indigestion.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  8. #8
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

    Default Re: One database for two websites

    @kuroi & schoolboy

    so, if I understand that right, using the same account with 2 stores in 2 separate subdomains should work just fine as long as one uses the different prefixes? Have to give this one a go over the weekend on my local machine.

    Thanks to all of you - time for beddies

  9. #9
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

    Default Re: One database for two websites

    This is one interesting thread indeed!

    Quote Originally Posted by kuroi View Post
    ... err guys. It can be done, and it doesn't require oodles of re-writing of core.

    For example:

    1. Create two sites in the same database with different database prefixes, e.g. "zen1_" and "zen2_". .........
    kuroi, how would one create two sites in the same database? I'd be very interested in reading the solution to this question.

    Thanks / Frank

  10. #10
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,267
    Plugin Contributions
    3

    Default Re: One database for two websites

    Quote Originally Posted by frank18 View Post
    This is one interesting thread indeed!



    kuroi, how would one create two sites in the same database? I'd be very interested in reading the solution to this question.

    Thanks / Frank
    Safest way is to use the standard zencart INSTALL procedure for a new website. Point the install to the SAME database you are using for your existing site

    When prompted (during setup), for a database prefix, put the desired prefix into the input field.
    20 years a Zencart User

 

 

Similar Threads

  1. Two Websites Sharing the Same MYSQL Database
    By limelites in forum Installing on a Linux/Unix Server
    Replies: 2
    Last Post: 25 Nov 2012, 05:26 PM
  2. Two Websites / One Database
    By irishshopper in forum Basic Configuration
    Replies: 4
    Last Post: 22 Nov 2010, 10:38 AM
  3. Two websites, one items database possible?
    By fritzy in forum General Questions
    Replies: 2
    Last Post: 25 Nov 2008, 11:26 PM
  4. Two websites from the same database.
    By bigjoed in forum General Questions
    Replies: 5
    Last Post: 14 Sep 2007, 03:04 PM
  5. One PayPal account - two websites?
    By Peekay in forum Addon Payment Modules
    Replies: 1
    Last Post: 20 Jun 2006, 12:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg