Importing a specific column into phpmyadmin database - php

I have been given an excel document which contains information about different embassies, their contact numbers etc. Most of this information is in the database already, but I need to extract one column from this file (emails) and insert it into a specific column (emails) in the database.
Is this possible, or can you only import an exact copy of what you want in the database?
Thanks for any help

Export the table from phpmyadmin as CSV for excel -
drag it into excel -
add the desired column -
Save -
export the table again from phpmyadmin as .sql -
copy the table creation(Not the data) -
delete the table from phpmyadmin-
Run the table creation query so you now have a blank table -
Import the excel csv.
IMPORTANT: backup your database

You may want to make a script with php-excel-reader which goes throught every row in the file, and updates the corresponding database row. I don't think that you can import a file "selectively" in phpMyAdmin.

Related

Load csv into MySQL, using a new table

I am using phpMyAdmin to load a CSV file into a MySQL table but, does the table have to be created before the load?
I have read that if the workbench is used ( Import a CSV file into MySQL workbench into a new table dynamically ) the latest version creates the table on the fly but, is this possible with phpMyAdmin.
Here is the code that doesn't work
load data local infile '/Users/...'
into table skin_cutaneous_melanoma
fields terminated by ','
lines terminated by '\n'
Error is:
#1146 - Table hospital.skin_cutaneous_melanoma' doesn't exist
Sure, phpMyAdmin can do this.
From the main page, look for the Import tab. This is, of course, how you expect to import any file including if you already have the database and table created, but if not phpMyAdmin creates a temporary database and table for you using generic names and best guesses as to the data types for your columns. Note that this is probably not the ideal structure, but is the best guess based on the existing data in your database. For best results, you'll probably want to put the desired column names at the top of your CSV file and select the corresponding option during import, or rename them after import (likewise with the database and table names) -- but it is absolutely possible to do the import to a new table.

How to export Table to CSV along with column names in PHPMYADMIN

I am trying to export the users table into CSV format using PHPMYADMIN but i get only the records and not the coloumn names. So How to do that? I am trying to import a CSV but it needs coloumn names so i want to have a csv that has column names !
where you download table into csv
just click on "put column name in the first row. check below image

Update MySQL Table using CSV file

my Current MySQL table employee_data has 13k rows with 17 columns. The data in the table came from a CSV file Employees.csv. after importing my csv data I added a new column 'password' (so its not in the csv file) Password is edited and accessed via a web portal. I now have an updated csv file and I want to update my main table with that data but I don't want to lose my password info.
Should I import my new CSV file into a temp table in my database and some how compare them? I am not sure where to start and I am open to recommendations.
I am now realizing I should have kept my password info in a separate table. Doh!
I guess I could created a php file that compares each row based on the employee_id field but with 13k rows I am afraid it would time out possibly.
I would do it like this :
Create a temp table using CREATE TABLE new_tbl LIKE orig_tbl; syntax
use LOAD DATA INFILE to import the data from the CSV into the table
Use UPDATE to update the primary table using a primary key / unique column (perhaps employee_id)
I have worked with tables containing 120 million lines and imported CSV files containing 30 million lines into it - this is the method I use all of the time - much more efficient than anything in PHP (and thats my server side language of choice)
Try other tools other than php based ones phpMyAdmin
MySQL workbench is a great tool,
based on you connection it will take a while to query the database with your data.
There are workarounds with php timeout limit,
set_time_limit();

modify csv with php before import / upload with php

I want to upload a csv to a database with php, but before i do that i want to modify some of the content.
The database table the csv will come from has 3 columns: id, postcode, debt_amount
The database table the csv will go to has 4 columns: id, postcode, debt_amount, count
What i want to do first is modify the full postcode to just show the first part before the 'space'.
Then i want to consolidate all the rows that have the same modified postcode, this will do two things:
Count the number of rows with the same modified postcode and place the total number into the consolidated row in the column 'count'.
Add up the 'debt_amount' column for the same modified postcode and put the total amount into the consolidated row under the 'debt_amount' column.
These processes would need to run together.
After that is done i want to upload it to the database.
I don't know if this is the best way of doing it, or if i should process the data from the first database first and export it into a CSV, to just allow me to upload the CSV on the other database.
Any help on either process would be good.
Thanks
I think it is best to process this data in MySQL itself. You may decide if you would like to process it in the source database or the target database.
So, if the processing involves:
modify the postcode
count #rows with same modified-postcode
sum debt_amount for same modified-postcode
Either do the processing in the source database, store the results in a temporary table, generate the CSV and then import to the target database. Or generate the CSV from the source DB, import to the target database in a temporary table, do the processing and store the results to the final table.
Do the standard file upload.
Read the CSV content from the temporary upload file.
Process the CSV Data (e.g. with SplFileObject­Docs.
Insert the processed data into your database.

Can I create a mysql database where the data is imported from excel files then displayed through a UI

I wanted to know if it would be possible to import an excel file into a databse? The columns for the MySQL database would have the same columns that the excel file would have and the title of the excel file.
So for example if I have a file named BL#123456 I would like to be able to take the data in that file and have it outputted to a user as "x y z a b c BL#".
I think I understand the process of data import from excel into MySQL the only thing is the file name to appear along side the columns.
Also I would be using a PHP script to import the data.
EDIT: How do I get it to import the file name as well as the data
Would it work if you did this?
1) create your table (include an additional column for the file name)
2) import a spreadsheet (you probably have collected the file name at this point, so stick it in a variable)
3) after importing each spreadsheet, run an update on your table UPDATE TABLE set fileName = $variable WHERE filename is null

Categories