Mass Updating A MySQL Database
One facet of textlinkcenter.com that I’ve been concerned about is the few sections where, using a cron job, I would have to update every record in a database when a given value. I thought I would have to pull out 2 zillion records, store them an array, and then re-insert them. Well, it turns out that MySQL is a little less primal than I had originally thought. In fact, it’s pretty damn good!
So, it turns out the query is very very simple.
Make a MySQL connection (which I store in a function)
db1_connection ();
Create / define the MySQL query
$query = “UPDATE test SET status1=50 “;
Run the query
$result = mysql_query($query) or die(mysql_error());
This particular MySQL query is quite simple. I will set status1 to equal 50 in every row of the database.
Of course, I could add the usual WHERE clause or even create some crazy MySQL functions.
Basically, what I thought was going to take some annoying php programming and possibly heavy resources is a piece of cake when done with MySQL.
Brandon