How to update SQL Query when a new column is added - php

I was wondering if anyone could help answer this question. I currently have an SQL Query that's being displayed into a table using PHP. I use a separate PHP file to upload data to mySQL table and when I update my table with a new column I have to rerun the SQL Query to get it to update into the PHP table. I was wondering if there was a way using PHP to automatically run that SQL Query when there has been an update to the table.

You can use AJAX and it to run in every second or you can use
meta tag : refresh
this will refresh page with php table

Related

Inserting data in a particular column where login id is already present

I want to write an sql command in PHP in which I want to insert a data in a particular column having particular data already present in that row.Here is the image where I want to insert 1_day_device to a particular 1_day_id
Also, how can I autodelete a row after a certain time? Like, in the image I want to delete one complete row after one day. I am using PHP for server-side.
I think you are looking for the update query with particular 1_day_id. Try with the below query.
UPDATE your_table_name SET 1_day_device='".$device."' WHERE 1_day_data='".$data."'
For delteting the records please follow this link Delete row from database automatically after 24 hours

Getting SQL for already populated tables? PHP My Admin

Using MySQL I can run the query:
SHOW CREATE TABLE employee;
And it will return the create table statement for the specified table. This is useful if you have a table already created, and want to create the same table on another database.
Is it possible to get the insert statement for an already existing set of rows, so that if a blank db with the tables created is set up, the sql can be pasted into the query box & all the tables will be populated exactly the same as the original?
Thanks
Example of data populated in the table, retrieving the sql for this.
Check the following link for exporting DB from phpmyadmin
https://mediatemple.net/community/products/dv/204403864/export-and-import-mysql-databases

How to add values simultaneously to the two related tables in MySQL?

I have this two tables:
I also have a dynamic form in which it contains table and the user can add rows and the data from it will be inserted in tblcamealsformdetails but the basis for inserting it is the id from tblcamealsform. How do I insert all the values to the two tables simultaneously?
Here's my form:
You will enter data first in table tblcamealsform. You insert ID from that query.
That ID you will use then to insert the rest of the data, along with the insert ID, in table tblcamealsformdetails.
So you don't do it simultaniously. You add the dependencies first.
To get the insert-id from the last query you executed, you will need mysql_insert_id().
See http://php.net/manual/en/function.mysql-insert-id.php
In answer to the comment what will happen if multiple users use the form at the same time:
Since you open a mysql connection at the top of your script which will result a unique connection pointer and all of the mysql-functions you call automatically reference to that pointer I think mysql_insert_id() will always reference to the latest query performed by the current connection. So another thread by another user would not interfere with this.
Please note that I am not 100% sure about this though.
Anyway: I am using this for about 10 years now some of which include high-traffic websites and I have never experienced any problems using this method, so in my opinion you can safely use it.
There is one exception to this:
You must always call mysql_insert_id() immediately after executing the query you want the ID for. If you execute any other query in the meantime (for example, you call a method of another object which performs an insert-query) mysql_insert_id() will return the ID of that query instead.
This is mistake I have made in the past and which you have to be aware of.
I'd like to point you using LAST_INSERT_ID:
when doing multiple-row inserts, LAST_INSERT_ID() will return the value of the first row inserted (not the last).

Compare data before and after update php mysql

How can I compare data before and after update PHP and MySQL?
If I add some data in the database that can be updated, is there a way of comparing the newly updated data with the previous data?
Yes, that is what TRIGGERS are for.
Using the CREATE TRIGGER syntax you can create a trigger before an UPDATE or INSERT
CREATE TRIGGER insert_trigger_name BEFORE INSERT ON table
or
CREATE TRIGGER update_trigger_name BEFORE UPDATE ON table

PHP PDO Firebird inserting

I'm new in Firebird but I'd like to write a small script in PHP that reads a CSV file and fills an existing Firebird db with its data.
The problem is I don't really know how to use the autoincrement generator. I've googled a lot but it's still a mistery for me. There is a gen_main generator defined in the db and I can use it in the IBExpert's query builder but cannot in PHP...
I saw a function named ibase_gen_id, what is the "PDO-way" of it?
What is the process of inserting a row that has an autoincremented field with PDO?
Thanks in advance!
NOTE: I have never used PDO, so I can't comment on PDO specifics.
Depending on your exact needs you can use: NEXT VALUE FOR
NEXT VALUE FOR <sequence-name>
or GEN_ID
GEN_ID(<sequence-name>, 1)
To get the next value of the sequence/generator.
You can either use these directly in your INSERT statement, or first issue a SELECT query against RDB$DATABASE to retrieve the value yourself before inserting: in Firebird you need to use a SELECT to retrieve values, and you always need to select against a table. RDB$DATABASE is guaranteed to contain only one row (like Oracle's DUAL).
So you need SELECT NEXT VALUE FOR GEN_MAIN FROM RDB$DATABASE or SELECT GEN_ID(GEN_MAIN, 1) FROM RDB$DATABASE to get the next sequence value.
In general however I would advise you to add a trigger to do the auto-increment for you, see Firebird Generator Guide for details. You can then use INSERT ... RETURNING <column-list> to retrieve the generated id.

Categories