Multiple Databases in a Single Table?
Multiple Databases in a Single Table?
Hi all, happy holidays!
Before I try going off on my own here, I should ask: Is it possible to access two or more databases within the same Editor table?
My case:
--I have a database called Inventory which is full of tables.
--I have a database called Tutorials which is full of tables.
--In both dbs I have duplicated a few tables based on categories (both dbs have MetaCats, Categories, and Subcats tables).
Not only is this duplication inefficient, it also leads to a number of issues which I am sure you can imagine.
I'd like to create a new database called Categories, which has Metacats, Categories, and Subcats tables, and thereafter access the Categories database from both the Inventory database and the Tutorials database.
I hope I am making sense here lol:)
I've previously been able to link different tables within the same db, but within different databases seems a different animal to me. Is there a standard way of doing this, if it is even possible?
Thanks as always,
Shawn
This question has an accepted answers - jump to answer
Answers
As in two different database connections? Or do you have a user which has access to both databases? What database are you using here - MySQL, SQL Server, Postgres?
Allan
I'm running XAMPP on a local computer, full access to Mariadb.
Okay, with Mariadb (and MySQL by extension) you can use notation such as:
In other databases such as Postgres that sort of syntax would be schema first, then table and finally column, but MySQL / Mairadb is a little different.
So you can do things like:
And add joins etc as needed. Just add the database name as a qualifier.
Allan
An elegant and very much appreciated solution. Thank you, Allan:)
Hi Allan (and all),
Now that I have created the unique categories database (with metacats,categories,subcats tables), I'm not sure how to modify the php file. For example, in my products table, I'm currently linking to internal metacat,category, and subcat tables like this:
This works when using 'select' type in the JavaScript:
Then connect the 3 tables:
To disconnect the internal metacats, categories, and subcats tables and connect to the new Categories db with the same 3 tables, would I simply add the new database name as dot-notation to the last part of the JS above, i.e.:
and do similarly with the last part of the PHP:
Am I understanding the concept here, Allan?
Thanks as always,
Shawn
Can you add
->debug(true)
immediately before->process($_POST)
and then send me a copy of the JSON that is returned from the server-side when the data is loaded?Thanks,
Allan
I've added the debug line, but I'm not sure where to find the JSON data. I'm guessing it's somewhere in the Chrome Console, but I'm not sure where to look...sorry:(
Right now, I get the following error:
DataTables warning: table id=products - Requested unknown parameter 'categories.metacats.metacat' for row 0, column 9. For more information about this error, please see http://datatables.net/tn/4
And then the same error two more times before loading my table, which works, not including the 3 external tables (metacats, categories, subcats) which are merely blank both in DT and DTE.
I would love a recommendation for debugging, if you are willing to offer one:) I'm using VSCode and NotePad++. I've not had the advantage of a debugger since my Flash/ActionScript days lol...
Quick update here. Strangely (to me), given that all of my naming conventions remained identical, all I had to do to move from the two, disparate, internal category tables from within my Products and Tutorials databases, respectively, all I had to do was point the config.php files to the categories database, and now everything pulls from there, in both cases.
In other words, all of my Products config files point to "products", all of my Tutorials config files point to "tutorials" and in both cases, where I join then to category tables, these joined tables come from the categories database, with the config file pointing to "categories", as noted.
One tiny change, very nice:)
Awesome - super to hear you've got it working now!
Allan