I am currently using PHPmyadmin to store data in my mySQL database. The android application I am developing requires the user to select some data and this data along with its attributes need to be stored in my mySQL database. I know I have to create a unique table for every user who downloads my application but how do I go about doing this without having access to the program which the user downloads ?
For eg: let us say there are two phones which download my application. I would want to create two tables in my database which the particular phone knows and can access
Creating one table for every user is a terrible approach. Instead you should create a users table, with a unique ID set to auto_increment, to generate those unique IDs. Then use separate tables to store the data you might need, referencing the user ID from the users table.
It might sound a little confusing, but there are lots of good reads about this on the Internet.
You can generate unique user id in php using uniqid(”, true) function.
Related
My app needs to use data from different websites. On these websites, there is a search with different chemical ingredients.
How can I programmatically copy this data from website to my realm database?
This database on Realm needs to be saved as a table which has 2 columns: ingredient name, description.
First of all, create an ID for each ingredient, receiving ID, Ingredient, Description. It's the best way to avoid conflict.
Second, you need to assemble a crawler, and this goes beyond your android application, maybe a network service that can be done even in java, identifying the information on each site and inserting into your database. So doing turn your android application get this information from the site.
I have an Android app and i want to allow my users to sync their local sqlite db with server.Since i have thousands of user's how should i set up my MySql database on server?As i see it there are two approaches,
1) One database per user plus one database to store user's credentials.Is this even possible since there will be thousands of different databases on server?
2) One database that holds all user's data.I was thinking i could add a field (user_id) on each table that identifies a user.I don't like though the idea that all user's data will be on the same table!!!
What's the best approach for my case?Is there something different i could try?
One database that holds all user's data.I was thinking i could add a field (user_id) on each table that identifies a user.I don't like though the idea that all user's data will be on the same table!!!
What is the best practice to store user data separately from the actual app data? The user data is a statistic and it will be collected during app usage. The database must be always updated but I have to keep the user statistic untouched. Can I store for example the statistic on one table? but can I keep this table when the App will be updated?
Update:
Sorry, I think my question was misunderstood. What is the best practice to manage two kinds of Data?
Save all data in one database and save the User-Data in seperetly tables? or
Create two Databases, one for App-data and one for User-data?
I'm not sure exactly of your question, but yes, you can have multiple tables in SQLite. So you can have one table for the user, call it tblUserStatistics and then other tables for the app, or depending on the data, the app information could be stored in preferences.
Yes, you can store your statistics in one table, but it's structure depends on what you want to save. If you want to save only numbers, you can create a table with 2 columns (1st one an ID and the second one the value you want to save), and update your rows when your data changes. If you've got multiple types of data to be saved (numbers, text, dates, whatever), you must create different columns with different data types, but still, you can do it. For your other questions the answer is yes, your table will be kept after you update your app, because it gets saved in a database which doesn't get modified when the user updates the app, just make sure that when you create the new version you don't change the name of the database.
I have a bit of a theoretical question for which there is no code yet as I am still just in the thinking stage. I want to update an app to allow users to share their data with others through DropBox Datastore or something like that. However, when a user creates data which get populated into multiple sqlite tables on the device, each table has an auto-incremental integer as a primary key that is used as a foreign key in other tables to link the data.
If there is more than one user actually creating the data and sharing it then the primary key columns are obviously going to be an issue. If I download the data and store it locally I obviously can't insert user 1's key value in user 2's data table, firstly because of the auto-increment and secondly because user 2 might already have data that is not shared saved with that key value.
I have thought about a few options but nothing is particularly appealing or robust. I was thinking about creating a UUID to identify the device, that value would have to be stored in each of the tables and the primary key would be a combination of that column and the current primary key integer which would obviously have to have the auto-increment removed. So to pick up all related data from each table the id column and UUID column would both have to be used.
I feel like there must be a more robust method of achieving this though, any one have any better suggestions?
If I'm understanding well you need some sort centralised database in the cloud to communicate with your local app, is that right?
A client should never create the ids for such a system. A usual practice on these cases is to always have a remote id which is created by your DB in the cloud, and whenever you don't have this value yet, you can have a fallback value (local id created locally - which is different from the remote one).
So, to illustrate my words we could set the following example. Your app stores messages in database. Say you create messages with a local id 1,2,3. Those ids will never be meant to be unique in your central database in the cloud. Instead, you'd just use them as a local fallback. As soon as you can send those 3 messages to your centralised database, it'll give them 3 new remote ids you'll use for unique means (ie.: 35, 46, 54).
Note that when you have multiple requesters/users accessing one same database there's not such way to assure uniqueness unless you follow the explained approach, or you query a certain number of unique ids in advance and on demand to your database in the cloud.
Keep in mind, that the actual truth can be only delivered by the databases in your servers.
Currently I have developed an android application that uses a local sqlite database per installation. The database comes pre-populated with static tables, and the entire point of the application is to allow the user to assign dates/comments with the pre-populated information in each table.
I am looking to bring this online, and move the database to a mysql format, allowing access via desktops and other mobile devices. Is the best way to handle this to assign each new user a new database?
I would strongly avoid creating multiple databases, and instead add relationships to the existing database structure you have with a users table. Each user has an association to each existing object. Keep in mind sharing with other users in the event that you may want to allow one user to see another user's info.
My suggestion is provide an update to the app where after the first launch after updating it pushes their information to your MySQL database and inform the users that they can access their data via other methods now.
how many user to you expect? I would use only one database with a user table instead of hundreds/thousands of databases.
One table for all users (only with user info like id, email, password, etc).
Another table with comments (with user id and his comment), so that you can add as many comments per user as needed. If dates are related to comments put them on this table, else another table for dates as well.