Sometimes it is critical to ensure a group of queries are all executed successfully to maintain the integrity of our data. Let's say we have a banking app where we need to subtract funds from one account and add funds to another:


$mysqli->query ("UPDATE 'accounts' SET 'balance' = 'balance'-1000000 WHERE 'user' = 'Bob'");
$mysqli->query ("UPDATE 'accounts' SET 'balance' = 'balance'+1000000 WHERE 'user' = 'Fred'");

What if one of the queries fails? To mitigate the chances of misplacing our millions due to some possible error we must ensure that both queries are executed with the expected result before committing any changes to the data. This where transactions are useful. We can run the queries, then check if some conditions are met before committing the changes in the data:

Applies to:

  • PHP 5.4
  • MySQL 5.1.4
  • Databases initially setup with collation 'latin1_swedish_ci'

What
Another article trying to help people display foreign characters on their website without the funny question marks in diamond symbols and how I solved it in my case.

What?
A quick article showing my MySQL statement when I want to remove all the accents from foreign characters and return the English equivalent.

Why?
A content management system (CMS) that I'm working on has just gone international and started including the names of places in other countries. This is nice but its search engine doesn't work properly as it thinks "riviere" is different to "rivière". We need to ensure that a search for any of these kind of words will return results of similarly typed/sounding words.

How?
Here's just a splurge of SQL but I use this often enough:

What?
A quick article on how to trim in MySQL along with getting rid of any leading or trailing tab characters.

Why?
I use MS Excel for organizing data and then converting to MySQL commands. Unfortunately, the MS Excel software adds tab characters to delimit the columns...

How?

UPDATE `mytable` SET `myColumn` = TRIM(CHAR(9) FROM TRIM(`myColumn`));
Source: Stack Overflow - How to Remove Tabs