Category Archives: MySQL

Insert data into two tables of different databases on same instance

If both databases reside on the SAME MySQL server (and use the same user and password to connect). You simply establish the connection without picking a database, then put the name of the database in front of the table name like: INSERT INTO myDBname.myTableName (myKey) VALUES (myValue); If you have a connection to one database…
Read more

Check to see if MySQL record exists

If you have ever had script that you need to check before updating/deleteing a MySQL record here is a quick code to check: if(mysql_num_rows(mysql_query("SELECT userid FROM plus_signup WHERE id = '$userid'"))) { // Code inside if block if userid is already there }
Read more

Swapping Column Values in MySQL

If you ever need to swap column values in MySQL here is how: UPDATE TABLE s1, TABLE s2 SET s1.SWAP_A=s1.SWAP_B, s1.SWAP_B=s2.SWAP_A WHERE s1.KEY=s2.KEY Check out this article to read more.
Read more