Insert data when empty and update it when data exist
With so many function provided in mysql plus lazy, It seem like finding gem for replace my old approach
duplicate data isn’t good, I must search for exisiting data, in general : insert data to table when no data with that value exist and update table if data exist
For example :
I have table A with field :
1. id, integer 11 primary key auto increment
2. name, varchar 25
3. address, varchar 100
4. phone, varchar 20
5. username, varchar 10 unique
a common operation to insert data is :
Checking for data, ex :
$check_data = mysql_query("select * from A where username =’$user’");
if(mysql_num_rows($check_data)>0) {
do update data
mysql_query("update A set bla..bla..bla");
}
else {
insert query here
mysql_query("insert into A bla..bla..bla");
}
after find "replace()"
mysql_query("replace into A (field1,field2) values(’values1′,’values2′)")
Yes, I still need to do research for another ‘glitch’ possibility in current application.
From mysql manual :
As long index exist for that table, like primary key or unique for helping mysql to find duplicate data or not.
Yes, replace don’t insert please
- Top Forum Posters Required by ahmansoor
- Project for Edmund by DorisC
- Nonpublic project #328415 by slipp
- Oscommerce small CCGV +Affiliate fix by fullecommerce1
- Banners design for a website, splash page presentation and sell page design by bullco
- Project for BeiManiago #2 by uchoa55
- Nonpublic project #328412 by bunnyg
- Number of small changes to 2 websites - pls read details by sanet
- Need quick fix for OSC site by flyhead64
- Project For "creator115". by sunconsultancy1


No Comment
Random Post
Leave Your Comments Below