temp tables & web application - php

I'm trying to develop a web application for work, using PHP, MySQL and jQuery.
The main aim of the application is to store information about the work we do for our customer, so that we can give them detailed reports at the end of the year.
an example of what I'm trying to accomplish:
a report would be created, using a customers details
entries would be added to this report documenting the work that has been carried out.
then both, report & entries would be inserted into there actual tables
I'm wanting to use temp tables to store the information so that I can use it between pages but looking to see if this is the best way of accomplishing this.
Thanks
D

Temporary tables are deleted automatically when the connection to the database is closed. In PHP, this is usually done after each page request. Use normal (i.e. non-temporary) tables to gather report data for all customers. Use foreign keys to link reports to customers and report entries to reports.

Related

How do i save notifications in phpmysql database for several users without overloading my database records

I fear that i can easily create reptition in my database while trying to ensure that all users in my db can view the same message. The problem is i need to be able to send from my admin area a message and have all users get notified and also have the option to mark messages as read. i know i ought to create two tables but how to write the sql command to generate the message for all users is becoming frustrating. this might probably be one easy task but i need help
i tried creating two tables in my Db. Notification and has__notify.
the notification saves the message with its title and date created while (has__notify) on the other hand contains columns like notificationID(foreign key), userID(foreign key)- to know which user has read the message, dateRead.
however, i think my implementation is wrong cause, i am a bit confused already.
By default a table would never be locked during insert. If you want be sure that data was stored you can use a transactions.

PHP: Query inside text log files instead of database records

I have a PHP application which generates many logs.
Since I want allow the application administrators to search logs based on parameters such as Used Id or Event Id I store whole logs in MySQL database. It reduces performance of my log table in database and I decided to move my logs to text log files instead of database.
However I have the problem to search through log files or query them and display the result to queries of administrators.
Are there any suggestion to overcome this problem? Are there any practices for this, since this seems a common problem for all application with large number of user.
Are there any practices for managing logs in
You can add your logs to a document-oriented database like (mongodb, ElasticSearch, Redis).
Alternatively, you can use free apps like Prometheus and grafana to view and add alerts (demo).

Best way to update data in mysql online database

I have an online sql database with a few tables for users matches and bets. When I update the result of any game, I need the status of all bets containing that game in the bet table to be updated. So for example if I update game 8 with the result home win I need all bets which have game 8 in them to be updated as either lost, won or still open.
The way I do this currently is that when the user turns on my android app, I retrieve all the information about the games and all the information about the user's bets using asynctasks. I then do some string comparisons in my app and then I update the data in my database using another asynctask. The issue is that this wastes a lot of computation time and makes my app UI laggy.
As someone with minimal experience with php and online databases, I'd like to ask is there a way to carry out these things in the database itself either periodically (every 3 hours for example) or whenever the data in the gamestable is changed using a php file for example which is automatically run?
I tried looking for some kind of onDataChanged function but couldn't find anything. I'm also not sure how to make a php file run and update data without getting the app involved.
Another idea I had was to create a very simple app which I wouldn't distribute to anyone but just keep on my phone with an update button which I could press and trigger a php file to carry out these operations for all users in my database.
I would appreciate some advice on this from someone who has experience.
Thanks :).
You can easily execute php script periodically if your hosting provider supports script executors like Cron.
About updating game status multiple times, first check tables engine. If you are using engine like InnoDB you can create relationship between those tables, so updating status of one row will affect all connected to them.

Add user registration and subscription to a PHP MySQL web app

I've been working on a web app for a few months now. It's a PHP and MySQL driven database app which relates objects between each other.
I'd like to add functionality so that someone could register to use it and set up a monthly subscription. When they log in the app would simply populate with data from their own database.
I've done some scouring online but I'm struggling to find a starting point for adding this sort of feature.
The app relies on half a dozen tables within a database. So I'm also not sure if creating an individual database per user is practical.
Creating a db per user is very rarely the way to go - it's complicated and has very few benefits with lots of drawbacks (eg maintaining multiple simultaneous Db connections as most libraries only connect to a single Db). What you really need to do is create a user table and then tag various records with a UserId.
When a user registers, create a new User record, then create their new entries in other tables all referencing that Id. (Actually, only the "root" of each relational object needs a UserId eg If you have Order and OrderItems only the Order table needs a UserId)
Without more detail, it's impossible to help further.
Incidentally, the only time you should consider db-per-user is if each user requires unique tables (in which case your app would have to be very complex to actually use the data) or if there are security concerns re: storing data together (more likely with multiple clients than multiple users).

MySQL CRM database dilemma

I'm working on making a consumer CRM system for my boot-strapped startup, where we'll use MySQL. We're moving from an old paper and pen method of tracking leads and referrals, to a digital method for our dealers.
The database will have a standard fields, like lead name, spouse, jobs, referral type, referrer, and lead dealer. This is easy, almost child's play.
Now is the part I'm having a hard time figuring it out. I want to track all the attempted contact dates and responses, and appointments that have been set or reset. The system is going to be web-based, with the front-end in PHP.
I thought about doing nested tables, but I don't want to use Oracle or PostgreSQL, as I like the familiar setup of MySQL.
For the sake of feasibility, say I have 4,000 leads, and each lead is going to be called on average 30 times. So I'll have 120,000 data points to track.
Would it be advisable to:
Make a two dimensional PHP array in the field, to keep track of these metrics.
Have a contact table with all 120k in it, that the application pulls when these metrics are needed
Have a contact table for each lead, which keeps track of all needed metrics
I would make one table for contacts. Add a column to record whether the contact was successful or not.
I would also use MySQL's table partitioning by lead, if many of the queries will be to report on specific leads.
But I second the comment from #Bryan Agee that you should consider carefully before implementing a CRM system from scratch on your weekends.
Start with the table of just the leads. Ideally, it should be filterable and searchable and sortable. Look into the jquery datatables plugin. You can have a table that's paged and pulls its data using AJAX from the server. That way you only need to query and return a few records at a time.
Then create a second table that pops up when the user clicks on the contact. This one is also AJAX and displays the contact history for that particular contact.
This way you never have to query and return the full list, especially if you have 4000, which would be a pain not only for the server but for the people using the system.
Have a contact table for each lead, and add data to it every time action(Contact) is made. It will also give you count and other metrics and it will be easy to implement and track.

Categories