I am working on a project with a bigger database structure then I have ever used before. I have questions regarding accessing certain tables.
I am now designing my ERD and have several Module tables
"Modules", "SubModules1" and "SubModules2".
As shown in the diagram below, Modules has an 1-m relation with SubModules1 and SubModules1 has a 1-m relationship with SubModules. There is a Bugs Table in which I want to store bugs linked to the module or submodule it belongs.
Question:
Is it necessary to connect all the Module Tables with Bugs Table separately, or is it possible to access all the SubModules through the Module table, since that one is connected to the SubModule1, etc...?
Note: Requirement is Data must be accessed from DB using PHP + Laravel 5.3 Framework
Related
I am new to MySQL databases and I'm trying to create a web stock and production database, using PHP.
In this inventory software, I am trying to create a table in which products are created and also their components inserted. But if a product has a different number of components, I wanted to know if there is any way to add more components columns from the management page of the website.
Another thing is that these components are taken from another table, and as long as a new product order is created, the quantity of those used components should be subtracted from the components table. (but this is a major issue, solving the first issue should be enough for now).
Yes, you can add, or remove, columns from a database table at any time.
However, I would not do this. You have to try and design a database that can handle products with a varying number of component. Normally this would be done this way:
Create a table for your products.
Create a table for your components.
Create a linking table product_components, to indicate what components a product consists off.
See: Using linking tables for many to many relationships in MySQL
You need to know about relationships in mysql. There are basically 3 types(some may say 4 though) of relationships available in a relational database like mysql.
Here according to your description you can use
1 to many
many to many
relationship in your database. This may help you-
https://afteracademy.com/blog/what-are-the-different-types-of-relationships-in-dbms
Friends, I am building a service application and would like to see a gross suggestion to achieve.
The core of the application is to manage research projects, hence it will have a group of users, who belong to an organization, who login and manage their own projects. Many organizations carry out such projects, which are identical in nature. The project management has identical database tables and schema (across institutions). I have designed a plan as follows:
Database-1: A common database users table (all institutions together) get authenticated by querying this table. This table has a institutional code corresponding to each user as a column.
Database-2 (institutional code as its name): Based on the institutional code, all the project management is done by connecting to this database. Within this database tables will be present.
....
Database-x (institutional code as its name).....
All databases will have identical schema and identical user interface. Institute wise management is easy this way.
Now, using Laravel, i know i can connect to multiple databases. I have done this in codeigniter 3 but trying to migrate to Laravel 5.3 as models architecture is different between Codeigniter 3 and Laravel 5.3.
Any better suggestions. I know my query is not a pure question but this question is about implementation of a many to many relation.
Since all institutions will have same modules and same functionalities why are you creating multiple databases? I have successfully done a similar project as you, a Centralised CMS which integrate all church under one diocese in CodeIgniter.
Just add an institution id in all tables and query your table operation with institution id every time. Adding multiple databases will definitely decrease your project performance and increase complexity. An institution table will track all your institutions.
If you need more details about database structure and implementation please comment below.
I have successfully worked on mutliple database and mutltiple domain application.
In that I have created one table "branches" which stored the multiple branches details
like its database name, domain name.
I have set the record as domain= "branch1", database="db_branch1" in table "branches"
Also set the middleware which check the valid domain name and allow to associated routes for domain "branch1".
Once the main common database authenticate the user creditials it connect to branch database in main connection.
It can not explain in very short method, here I just explain the work flow. If you need more details I will explain it.
I'm developing an application using CakePHP (latest version) framework for PHP that will unite several instalations of a CMS with a single registration form. I'm using a MySql DB. The problem is that I cannot modify the CMS code, I can only modify the DB data since very frequent CMS updates will overwrite my modifications.
The idea is that the system will keep a master Users table as shown in the diagram with the shared data. The table model of the master Users table and the child Users table is the same, except for a few CMS installation specific columns (as shown in the simplified diagram).
Now I'm trying to figure out a way to reflect the changes I do on master (INSERT and UPDATE) to occur on all of the child DBs. So when I make a change in my CakePHP app I want those fields that are shared to be updated in all child DB instances.
One solution would be to write manual MySQL queries for every single action in the application but that seems redundant and annoying.
How could I make my app to repeat all of the queries I do on my MASTER on every CHILD. Basicly if I UPDATE the name of entry ID 5 in MASTER, that that same query is ran on all of the child databases (which will hold the same entry under the same ID but with a few additional columns).
You could do that easily with CakePHP's model triggers (beforeSave, afterSave...) BUT keeping all that stuff synchronized will soon become your worst nightmare. Instead, I would do something like this:
Master.User has (id, name, password, specData1, specData2...)
Child1.User is a mysql VIEW: CREATE VIEW User AS SELECT id AS id, name AS name.., specData1 AS specData FROM Master.User
Yes, you can create cross-DB views. For the CMSs Child1.User is a table, all operations CREATE/DELETE/UPDATE are transparently done by the CMS on the VIEW thinking its a table. (but Master.User gets updated)
I have two tables in DB (topic, topic_content):
what kind of entities i should create for symfony2?
I think, i should have something like this in my symfony structure (Entities/Topic.php, Entities/Topic_content.php) help me please..
Yes, you would create Topic and Topic Content. And likely also a User Entity (because user_id looks like a foreign key).
However, the idea in Symfony2 is to approach the application from the Model site instead of the database site. Quoting https://doctrine-orm.readthedocs.org/en/latest/tutorials/getting-started-database.html:
Development Workflows
When you Code First, you start with developing Objects and then map them onto your database. When you Model First, you are modelling your application using tools (for example UML) and generate database schema and PHP code from this model. When you have a Database First, you already have a database schema and generate the corresponding PHP code from it.
For database first, there is a generator that will derive objects based on your schema:
https://github.com/beberlei/DoctrineCodeGenerator
The recommended approach though is to have Doctrine generate the db schema from your Entities.
Quoting Getting Started - Generating the DB Schema
Doctrine has a Command-Line Interface that allows you to access the SchemaTool, a component that generates the required tables to work with the metadata.
It requires some setup, which is explained in the guide. Once you have that, you simply tell Doctrine to generate or update your schema, whenever your object structure changes.
I have a few custom tables in my Drupal database that were created manually.
Is there some Drupal module to allow viewing and editing records in custom tables?
Tables are simple, no joins used.
Or it's best to build some grid/record interfaces manually in custom module?
For reporting, the recommended way is likely to use Views integration. If your tables have primary keys, it's a simple matter of defining them to Views by implementing:
hook_views_api() to declare Views integration
hook_views_data() to declare the tables and their fields, assuming they use only simple data types
You can take the integration examples in views/modules/node.views.inc and views/modules/node/*. Module TableWizard can help you with this.
This still won't provide you with editability, though. For this, you could either build the module on your own using Form API, or import the content of these tables as nodes, and use drupal builtin editing on the nodes, assuming you do not mind the data being in node format after that.
You might consider using both Views and the new Data module:
The Data module provides
* an API for dynamically allocating tables for single-row records.
* an API for insert/update/delete operations and describing how tables join to each other.
* automatic views integration.
* a way to export table definitions to code.
The included Data UI module provides
* UI to add new database tables.
* UI to add or alter columns to existing tables managed by Data module.
* UI to define joins between tables.
* UI to solve conflicts between table in database and schema information.
* default views for tables managed by Data module.
* UI to add existing tables that are unclaimed by other modules to Data's table management.
keep an eye on this https://drupal.org/project/dba
they'll be coming up with these functionalities
ability to execute sql scripts and see the resulting output (ie, create/alter/update tables)
overview table listing including total row counts for each
ability to drop one or more tables at a time
ability to edit a specific row (using simple form)
ability to delete a specific row
in MySQL, ability to check and repair one or more tables at a time